Permalink
Browse files

Implemented new models and repositories for MongoDB.

  • Loading branch information...
1 parent ac5f91d commit 2e97bf22b6be169b487dae072cc36a4ef4d81df8 @erniep888 committed Apr 30, 2012
Showing with 550 additions and 104 deletions.
  1. +3 −3 source/ScrumTime.Foundation.Test/App.config
  2. +28 −0 source/ScrumTime.Foundation.Test/BugRepositoryTest.cs
  3. +2 −0 source/ScrumTime.Foundation.Test/ScrumTime.Foundation.Test.csproj
  4. +26 −17 source/ScrumTime.Foundation.Test/ScrumTimeInitializerTest.cs
  5. +26 −0 source/ScrumTime.Foundation.Test/StoryRepositoryTest.cs
  6. +3 −3 source/ScrumTime.Foundation/App.config
  7. +35 −0 source/ScrumTime.Foundation/DataAccessLayer/BaseRepository.cs
  8. +68 −0 source/ScrumTime.Foundation/DataAccessLayer/BugRepository.cs
  9. +20 −0 source/ScrumTime.Foundation/DataAccessLayer/ProductRepository.cs
  10. +20 −0 source/ScrumTime.Foundation/DataAccessLayer/ReleaseRepository.cs
  11. +43 −16 source/ScrumTime.Foundation/DataAccessLayer/ScrumTimeContext.cs
  12. +9 −12 source/ScrumTime.Foundation/DataAccessLayer/ScrumTimeInitializer.cs
  13. +44 −0 source/ScrumTime.Foundation/DataAccessLayer/StoryRepository.cs
  14. +4 −1 source/ScrumTime.Foundation/Models/Actor.cs
  15. +4 −3 source/ScrumTime.Foundation/Models/Artifact.cs
  16. +17 −3 source/ScrumTime.Foundation/Models/Bug.cs
  17. +17 −0 source/ScrumTime.Foundation/Models/BugPriority.cs
  18. +17 −0 source/ScrumTime.Foundation/Models/BugSeverity.cs
  19. +17 −0 source/ScrumTime.Foundation/Models/BugStatus.cs
  20. +13 −4 source/ScrumTime.Foundation/Models/Feature.cs
  21. +14 −0 source/ScrumTime.Foundation/Models/IScrumTimeModel.cs
  22. +5 −1 source/ScrumTime.Foundation/Models/Product.cs
  23. +8 −5 source/ScrumTime.Foundation/Models/Release.cs
  24. +4 −6 source/ScrumTime.Foundation/Models/Scrum.cs
  25. +3 −8 source/ScrumTime.Foundation/Models/ScrumTask.cs
  26. +10 −9 source/ScrumTime.Foundation/Models/Sprint.cs
  27. +6 −8 source/ScrumTime.Foundation/Models/Story.cs
  28. +17 −0 source/ScrumTime.Foundation/Models/StoryPoints.cs
  29. +2 −0 source/ScrumTime.Foundation/Models/Task.cs
  30. +7 −4 source/ScrumTime.Foundation/Models/Team.cs
  31. +45 −0 source/ScrumTime.Foundation/ReadMe-MongoDB.txt
  32. +1 −1 source/ScrumTime.Foundation/ReadMe.txt
  33. +12 −0 source/ScrumTime.Foundation/ScrumTime.Foundation.csproj
@@ -4,12 +4,12 @@
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
- <connectionStrings>
- <add name="ScrumTimeContext" connectionString="Data Source=|DataDirectory|\App_Data\ScrumTime_Compact.sdf" providerName="System.Data.SqlServerCe.4.0" />
- </connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
+ <appSettings>
+ <add key="ScrumTimeMongoDBConnection" value="mongodb://localhost/?safe=true"/>
+ </appSettings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
@@ -0,0 +1,28 @@
+using System;
+using System.Text;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using MongoDB.Bson;
+using MongoDB.Driver;
+using MongoDB.Driver.Linq;
+using MongoDB.Driver.Builders;
+
+using ScrumTime.Foundation.DataAccessLayer;
+using ScrumTime.Foundation.Models;
+
+namespace ScrumTime.Foundation.Test
+{
+ [TestClass]
+ public class BugRepositoryTest
+ {
+ [TestMethod]
+ public void SetDefaultBugInformationTest()
+ {
+ var bugRepository = new BugRepository();
+ bugRepository.SetDefaultBugPriorities();
+ bugRepository.SetDefaultBugSeverities();
+ bugRepository.SetDefaultBugStatuses();
+ }
+ }
+}
@@ -52,6 +52,8 @@
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
+ <Compile Include="BugRepositoryTest.cs" />
+ <Compile Include="StoryRepositoryTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScrumTimeInitializerTest.cs" />
</ItemGroup>
@@ -16,21 +16,6 @@ namespace ScrumTime.Foundation.Test
[TestClass]
public class ScrumTimeInitializerTest
{
- [TestMethod]
- public void FindTest()
- {
- var connectionString = "mongodb://localhost/?safe=true";
- var server = MongoServer.Create(connectionString);
-
- var database = server.GetDatabase("ScrumTime");
- var collection = database.GetCollection<Product>("products");
-
- var product = (from e in collection.AsQueryable<Product>()
- select e).FirstOrDefault();
- Assert.IsNotNull(product);
-
- }
-
[TestMethod]
public void SeedStoryTest()
{
@@ -45,15 +30,15 @@ public void SeedStoryTest()
{
Name = "Login Hide",
Narrative = "As an anonymous user, I need to see more of the screen prior to logging in so that I may see recent quotes.",
- Points = 5,
+ Points = "5",
Priority = 200
};
var storyParent = new Story()
{
Name = "Login Control",
Narrative = "As an anonymous user, I need to login so that the system provides authorized access.",
- Points = 13,
+ Points = "13",
Priority = 200,
Children = new List<Story>()
};
@@ -95,5 +80,29 @@ public void SeedProductTest()
Assert.Fail();
}
}
+
+ [TestMethod]
+ public void FindTest()
+ {
+ var connectionString = "mongodb://localhost/?safe=true";
+ var server = MongoServer.Create(connectionString);
+
+ var database = server.GetDatabase("ScrumTime");
+ var collection = database.GetCollection<Product>("products");
+
+ var product = (from e in collection.AsQueryable<Product>()
+ select e).FirstOrDefault();
+ Assert.IsNotNull(product);
+
+ }
+
+ [TestMethod]
+ public void BugRepositoryTest()
+ {
+ var bugRepository = new BugRepository();
+ bugRepository.SetDefaultBugPriorities();
+ bugRepository.SetDefaultBugSeverities();
+ bugRepository.SetDefaultBugStatuses();
+ }
}
}
@@ -0,0 +1,26 @@
+using System;
+using System.Text;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using MongoDB.Bson;
+using MongoDB.Driver;
+using MongoDB.Driver.Linq;
+using MongoDB.Driver.Builders;
+
+using ScrumTime.Foundation.DataAccessLayer;
+using ScrumTime.Foundation.Models;
+
+namespace ScrumTime.Foundation.Test
+{
+ [TestClass]
+ public class StoryRepositoryTest
+ {
+ [TestMethod]
+ public void SetDefaultStoryPointsTest()
+ {
+ var storyRepository = new StoryRepository();
+ storyRepository.SetDefaultStoryPoints();
+ }
+ }
+}
@@ -4,12 +4,12 @@
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
- <connectionStrings>
- <add name="ScrumTimeConnection" connectionString="Data Source=|DataDirectory|ScrumTime.sdf" providerName="System.Data.SqlServerCe.4.0" />
- </connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
+ <appSettings>
+ <add key="ScrumTimeMongoDBConnection" value="mongodb://localhost/?safe=true"/>
+ </appSettings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MongoDB.Bson;
+using MongoDB.Driver;
+using MongoDB.Driver.Linq;
+using ScrumTime.Foundation.Models;
+
+namespace ScrumTime.Foundation.DataAccessLayer
+{
+ public class BaseRepository<T> where T : IScrumTimeModel
+ {
+ protected ScrumTimeContext scrumTimeContext;
+
+ protected String collectionName;
+
+ public BaseRepository(String collectionName)
+ {
+ scrumTimeContext = new ScrumTimeContext();
+ this.collectionName = collectionName;
+ }
+
+ public IQueryable<T> GetCollection()
+ {
+ return scrumTimeContext.Database.GetCollection<T>(collectionName).AsQueryable<T>();
+ }
+
+ public T GetById(ObjectId Id)
+ {
+ return GetCollection().Where(m => m.Id == Id).FirstOrDefault();
+ }
+ }
+}
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MongoDB.Bson;
+using MongoDB.Driver.Linq;
+using ScrumTime.Foundation.Models;
+
+namespace ScrumTime.Foundation.DataAccessLayer
+{
+ public class BugRepository : BaseRepository<Bug>
+ {
+
+ public BugRepository()
+ : base("Bugs")
+ {
+ }
+
+ public void SetDefaultBugPriorities()
+ {
+ var priorities = scrumTimeContext.BugPriorities().AsQueryable<BugPriority>();
+ if (priorities.SingleOrDefault(m => m.Name == "Low") == null)
+ scrumTimeContext.BugPriorities().Insert(new BugPriority() { Name = "Low", NumericValue = 100 });
+ if (priorities.SingleOrDefault(m => m.Name == "Normal") == null)
+ scrumTimeContext.BugPriorities().Insert(new BugPriority() { Name = "Normal", NumericValue = 50 });
+ if (priorities.SingleOrDefault(m => m.Name == "High") == null)
+ scrumTimeContext.BugPriorities().Insert(new BugPriority() { Name = "High", NumericValue = 10 });
+ if (priorities.SingleOrDefault(m => m.Name == "Urgent") == null)
+ scrumTimeContext.BugPriorities().Insert(new BugPriority() { Name = "Urgent", NumericValue = 1 });
+ }
+
+ public void SetDefaultBugSeverities()
+ {
+ var severities = scrumTimeContext.BugSeverities().AsQueryable<BugSeverity>();
+ if (severities.SingleOrDefault(m => m.Name == "Trivial") == null)
+ scrumTimeContext.BugSeverities().Insert(new BugSeverity() { Name = "Trivial", NumericValue = 100 });
+ if (severities.SingleOrDefault(m => m.Name == "Minor") == null)
+ scrumTimeContext.BugSeverities().Insert(new BugSeverity() { Name = "Minor", NumericValue = 50 });
+ if (severities.SingleOrDefault(m => m.Name == "Major") == null)
+ scrumTimeContext.BugSeverities().Insert(new BugSeverity() { Name = "Major", NumericValue = 10 });
+ if (severities.SingleOrDefault(m => m.Name == "Blocking") == null)
+ scrumTimeContext.BugSeverities().Insert(new BugSeverity() { Name = "Blocking", NumericValue = 1 });
+ }
+
+ public void SetDefaultBugStatuses()
+ {
+ var statuses = scrumTimeContext.BugStatuses().AsQueryable<BugStatus>();
+ if (statuses.SingleOrDefault(m => m.Name == "New") == null)
+ scrumTimeContext.BugStatuses().Insert(new BugStatus() { Name = "New", NumericValue = 100 });
+ if (statuses.SingleOrDefault(m => m.Name == "Feedback") == null)
+ scrumTimeContext.BugStatuses().Insert(new BugStatus() { Name = "Feedback", NumericValue = 95 });
+ if (statuses.SingleOrDefault(m => m.Name == "Acknowledged") == null)
+ scrumTimeContext.BugStatuses().Insert(new BugStatus() { Name = "Acknowledged", NumericValue = 90 });
+ if (statuses.SingleOrDefault(m => m.Name == "Confirmed") == null)
+ scrumTimeContext.BugStatuses().Insert(new BugStatus() { Name = "Confirmed", NumericValue = 70 });
+ if (statuses.SingleOrDefault(m => m.Name == "Assigned") == null)
+ scrumTimeContext.BugStatuses().Insert(new BugStatus() { Name = "Assigned", NumericValue = 50 });
+ if (statuses.SingleOrDefault(m => m.Name == "On Hold") == null)
+ scrumTimeContext.BugStatuses().Insert(new BugStatus() { Name = "On Hold", NumericValue = 40 });
+ if (statuses.SingleOrDefault(m => m.Name == "Resolved") == null)
+ scrumTimeContext.BugStatuses().Insert(new BugStatus() { Name = "Resolved", NumericValue = 20 });
+ if (statuses.SingleOrDefault(m => m.Name == "Closed") == null)
+ scrumTimeContext.BugStatuses().Insert(new BugStatus() { Name = "Closed", NumericValue = 10 });
+
+ }
+ }
+}
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MongoDB.Bson;
+using MongoDB.Driver.Linq;
+using ScrumTime.Foundation.Models;
+
+namespace ScrumTime.Foundation.DataAccessLayer
+{
+ public class ProductRepository : BaseRepository<Product>
+ {
+ public ProductRepository()
+ : base("Products")
+ {
+ }
+
+ }
+}
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MongoDB.Bson;
+using MongoDB.Driver.Linq;
+using ScrumTime.Foundation.Models;
+
+namespace ScrumTime.Foundation.DataAccessLayer
+{
+ public class ReleaseRepository : BaseRepository<Release>
+ {
+ public ReleaseRepository()
+ : base("Releases")
+ {
+ }
+
+ }
+}
@@ -1,23 +1,50 @@
-using ScrumTime.Foundation.Models;
-
-namespace ScrumTime.Foundation.DataAccessLayer
+namespace ScrumTime.Foundation.DataAccessLayer
{
- public class ScrumTimeContext // : DbContext
+ using System.Configuration;
+ using MongoDB.Driver;
+
+ using ScrumTime.Foundation.Models;
+
+ public class ScrumTimeContext
{
- //public DbSet<Actor> Actors { get; set; }
- //public DbSet<Artifact> Artifacts { get; set; }
- //public DbSet<Bug> Bugs { get; set; }
- //public DbSet<Feature> Features { get; set; }
- //public DbSet<Product> Products { get; set; }
- //public DbSet<Release> Releases { get; set; }
- ////public DbSet<Scrum> Scrums { get; set; }
- ////public DbSet<ScrumTask> ScrumTasks { get; set; }
- //public DbSet<Sprint> Sprints { get; set; }
- //public DbSet<Story> Stories { get; set; }
- //public DbSet<Task> Tasks { get; set; }
- //public DbSet<Team> Teams { get; set; }
+ public MongoDatabase Database { get; private set; }
+
+ public ScrumTimeContext()
+ {
+ var connectionString = ConfigurationManager.AppSettings["ScrumTimeMongoDBConnection"];
+ var server = MongoServer.Create(connectionString);
+ Database = server.GetDatabase("ScrumTime");
+ }
+
+
+ public void DeleteAllCollections()
+ {
+ foreach (var collectionName in Database.GetCollectionNames())
+ {
+ Database.DropCollection(collectionName);
+ }
+ }
+
+ public MongoCollection<StoryPoint> StoryPoints()
+ {
+ return Database.GetCollection<StoryPoint>("StoryPoints");
+ }
+ public MongoCollection<BugSeverity> BugSeverities()
+ {
+ return Database.GetCollection<BugSeverity>("BugSeverities");
+ }
+
+ public MongoCollection<BugPriority> BugPriorities()
+ {
+ return Database.GetCollection<BugPriority>("BugPriorities");
+ }
+
+ public MongoCollection<BugStatus> BugStatuses()
+ {
+ return Database.GetCollection<BugStatus>("BugStatuses");
+ }
}
}
Oops, something went wrong.

0 comments on commit 2e97bf2

Please sign in to comment.