public ProblemServiceTest() { _conn = new DbConnexion("Test_LittleProblem"); _problemCollection = _conn.Collection <Problem>(CollectionNames.Problem); _problemService = new ProblemService(_conn); // Perform factory set up (once for entire test run) IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => c.UseDefaultConventions()); x.AddFromAssemblyContainingType <Member>(); x.Include <Member>() .Setup(m => m.Id).Use <ObjectIdDataSource>() .Setup(m => m.OpenId).Random(5, 10) .Setup(m => m.UserName).Random(5, 7); x.Include <Problem>() .Setup(p => p.Id).Use <ObjectIdDataSource>() .Setup(p => p.Text).Use <LoremIpsumSource>() .Setup(p => p.Title).Random(7, 12); x.Include <Response>() .Setup(r => r.Text).Use <LoremIpsumSource>(); }); // Generate one of these per test (factory will be a static variable most likely) _session = factory.CreateSession(); }
public ProblemServiceTest() { _conn = new DbConnexion("Test_LittleProblem"); _problemCollection = _conn.Collection<Problem>(CollectionNames.Problem); _problemService = new ProblemService(_conn); // Perform factory set up (once for entire test run) IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => c.UseDefaultConventions()); x.AddFromAssemblyContainingType<Member>(); x.Include<Member>() .Setup(m => m.Id).Use<ObjectIdDataSource>() .Setup(m => m.OpenId).Random(5, 10) .Setup(m => m.UserName).Random(5, 7); x.Include<Problem>() .Setup(p => p.Id).Use<ObjectIdDataSource>() .Setup(p => p.Text).Use<LoremIpsumSource>() .Setup(p => p.Title).Random(7, 12); x.Include<Response>() .Setup(r => r.Text).Use<LoremIpsumSource>(); }); // Generate one of these per test (factory will be a static variable most likely) _session = factory.CreateSession(); }
private void ValidateMember(Member member) { if (member == null) { throw new ArgumentException("It require a member so null values are not accepted."); } var existingMember = _connexion.Collection <Member>(CollectionNames.Member) .AsQueryable().Where(m => m.Id == member.Id).FirstOrDefault(); if (existingMember == null) { throw new ArgumentException("It requiere an existing member already persisted in db."); } }
public ProblemAggregate Get(string id) { Problem problem = _problemsCollection.AsQueryable() .FirstOrDefault(x => x.Id == new ObjectId(id)); if (problem == null) { throw new EntityNotFoundException("Could not find the requested problem. Problem Id was :" + id); } List <ObjectId> userIds = problem.Responses.Select(x => x.UserId).ToList(); userIds.Add(problem.UserId); var bsonObjectIds = userIds.Select(x => new BsonObjectId(x)).ToArray(); var query = Query.In("_id", bsonObjectIds); var members = _connexion.Collection <Member>(CollectionNames.Member) .Find(query) .ToList(); List <ResponseAggregate> responses = problem.Responses.Select(res => new ResponseAggregate { Id = res.Id.ToString(), Text = res.Text, Note = res.Note, Submitter = members.Where(m => m.Id == res.UserId).FirstOrDefault() }).ToList(); return(new ProblemAggregate { Id = problem.Id.ToString(), OpenedDate = problem.OpenedDate, Text = problem.Text, Title = problem.Title, Responses = responses, IsClosed = problem.IsClosed(), Submitter = members.Where(m => m.Id == problem.UserId).First() }); }
public MembershipService(IConnexion connexion) { _connexion = connexion; _membersCollection = _connexion.Collection<Member>(CollectionNames.Member); }
public ProblemRepository(IConnexion conn) { _connexion = conn; _problemsCollection = _connexion.Collection <Problem>(CollectionNames.Problem); }
public ProblemRepository(IConnexion conn) { _connexion = conn; _problemsCollection = _connexion.Collection<Problem>(CollectionNames.Problem); }
public ProblemService(IConnexion connexion) { _connexion = connexion; _problemsCollection = _connexion.Collection <Problem>(CollectionNames.Problem); }
public ProblemService(IConnexion connexion) { _connexion = connexion; _problemsCollection = _connexion.Collection<Problem>(CollectionNames.Problem); }
public MembershipService(IConnexion connexion) { _connexion = connexion; _membersCollection = _connexion.Collection <Member>(CollectionNames.Member); }
public void CreateProblemWillSaveItInDb() { var member = _session.Single <Member>().Get(); _conn.Collection <Member>(CollectionNames.Member).Save(member); const string title = "New Problem Created for test"; const string description = "Some description"; var problem = _problemService.CreateProblem(title, description, member); Assert.That(problem, Is.Not.Null); Assert.That(problem.Id, Is.Not.Null); Assert.That(problem.Title, Is.EqualTo(title)); Assert.That(problem.Text, Is.EqualTo(description)); Assert.That(problem.Responses, Is.Empty); var fromDb = _problemCollection.AsQueryable().Where(x => x.Id == problem.Id).First(); Assert.That(fromDb, Is.Not.Null); Assert.That(fromDb.Id, Is.Not.Null); Assert.That(fromDb.Id, Is.EqualTo(problem.Id)); Assert.That(fromDb.Title, Is.EqualTo(problem.Title)); Assert.That(fromDb.Text, Is.EqualTo(problem.Text)); Assert.That(fromDb.Responses, Is.Empty); }
public MemberRepository(IConnexion conn) { _connexion = conn; _membersCollection = _connexion.Collection <Member>(CollectionNames.Member); }
public MemberRepository(IConnexion conn) { _connexion = conn; _membersCollection = _connexion.Collection<Member>(CollectionNames.Member); }