public void SaveSomeDataShoulUpdateSomeDataInDatabaseAndSaveChanges()
        {
            var updateSomeDataCommand = BuildUpdateSomeDataCommand();
            var businessUser          = new BusinessUser
            {
                Id       = Guid.NewGuid(),
                Gender   = "SomeGender",
                Locale   = "SomeLocale",
                Location = "SomeLocation",
                Identity = new ApplicationUser
                {
                    Email = "*****@*****.**"
                }
            };
            var someDataDb = SomeDataMapper.UpdateSomeDataCommandToPersistanceModel(updateSomeDataCommand);

            someDataDb.BusinessUserId = businessUser.Id;

            var someDataDbSet = new List <SomeData>
            {
                someDataDb
            };
            var businessUserDb = new List <BusinessUser>
            {
                businessUser
            };

            var businessUserMockSet = new MockDbSet <BusinessUser>(businessUserDb);
            var someDataMockSet     = new MockDbSet <SomeData>(someDataDbSet);
            var contextMock         = new Mock <SomeDataContext>();

            contextMock.Setup(c => c.SomeData).Returns(someDataMockSet.Object);
            contextMock.Setup(c => c.BusinessUsers).Returns(businessUserMockSet.Object);

            var someDataRepository = new SomeDataWriteRepository(contextMock.Object);

            var updatedSomeData = SomeAggregate.Create(updateSomeDataCommand.SomeDataId,
                                                       "NewFirstName",
                                                       "NewMiddleName",
                                                       "NewLastName",
                                                       "NewTitle",
                                                       new Color("#c1d0c3"),
                                                       DateTime.Now,
                                                       new FacebookUrl(null),
                                                       Guid.NewGuid());

            someDataRepository.Save(updatedSomeData);
            var updatedDb = someDataRepository.Get(updateSomeDataCommand.SomeDataId);

            contextMock.Verify(x => x.SaveChanges(), Times.Once);
            Assert.Equal(updatedDb.Id, updatedSomeData.Id);
            Assert.Equal(updatedDb.Color, updatedSomeData.Color);
            Assert.Equal(updatedDb.CreationDate, updatedSomeData.CreationDate);
            Assert.Equal(updatedDb.FacebookUrl, updatedSomeData.FacebookUrl);
            Assert.Equal(updatedDb.FirstName, updatedSomeData.FirstName);
            Assert.Equal(updatedDb.LastName, updatedSomeData.LastName);
            Assert.Equal(updatedDb.MiddleName, updatedSomeData.MiddleName);
            Assert.Equal(updatedDb.Title, updatedSomeData.Title);
        }
        public void ShouldMapCorrectlyOnPersistanceModelToAggregateRoot()
        {
            var someData      = BuildSomeDataPersistanceModel();
            var aggregateRoot = SomeDataMapper.PersistanceModelToAggregateRoot(someData);

            Assert.Equal(aggregateRoot.CreationDate, someData.CreationDate);
            Assert.Equal(aggregateRoot.FacebookUrl.Value, someData.FacebookUrl);
            Assert.Equal(aggregateRoot.Color.Value, someData.Color);
            Assert.Equal(aggregateRoot.FirstName, someData.FirstName);
            Assert.Equal(aggregateRoot.Id, someData.Id);
            Assert.Equal(aggregateRoot.LastName, someData.LastName);
            Assert.Equal(aggregateRoot.MiddleName, someData.MiddleName);
            Assert.Equal(aggregateRoot.Title, someData.Title);
        }
        public void ShouldMapCorrectlyOnSomeAggregateToPersistanceModel()
        {
            var aggregate = BuildSomeAggregate();
            var mapped    = SomeDataMapper.SomeAggregateToPersistanceModel(aggregate);

            Assert.Equal(aggregate.CreationDate, mapped.CreationDate);
            Assert.Equal(aggregate.FacebookUrl.Value, mapped.FacebookUrl);
            Assert.Equal(aggregate.Color.Value, mapped.Color);
            Assert.Equal(aggregate.FirstName, mapped.FirstName);
            Assert.Equal(aggregate.Id, mapped.Id);
            Assert.Equal(aggregate.LastName, mapped.LastName);
            Assert.Equal(aggregate.MiddleName, mapped.MiddleName);
            Assert.Equal(aggregate.Title, mapped.Title);
            Assert.Equal(aggregate.BusinessUserId, mapped.BusinessUserId);
        }
 public List <SomeAggregate> GetSomeData(string userEmail)
 {
     try
     {
         using (var context = SomeDataEntities)
         {
             var businessUser     = context.BusinessUsers.FirstOrDefault(bu => bu.Identity.Email == userEmail);
             var mySampleSolution = context.SomeData
                                    .Where(k => k.BusinessUserId == businessUser.Id)
                                    .Select(k => SomeDataMapper.PersistanceModelToAggregateRoot(k)).ToList();
             return(mySampleSolution);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemple #5
0
        public void Create(SomeAggregate someData, SomeDataContext dbContext)
        {
            var someDatatoSave = SomeDataMapper.SomeAggregateToPersistanceModel(someData);

            dbContext.SomeData.Add(someDatatoSave);
        }
Exemple #6
0
 public SomeAggregate Get(Guid someDataId, SomeDataContext dbContext)
 {
     return(SomeDataMapper.PersistanceModelToAggregateRoot(
                dbContext.SomeData.FirstOrDefault(d => d.Id == someDataId)));
 }