Beispiel #1
0
        public void ShouldHaveCreatedEvent()
        {
            // Arrange
            Guid     expectedId           = Guid.NewGuid();
            Guid     expectedHouseholdId  = Guid.NewGuid();
            Guid     expectedSavingTypeId = Guid.NewGuid();
            string   expectedName         = "Name";
            string   expectedDescription  = "Description";
            decimal  expectedAmount       = 102.12m;
            DateTime expectedDate         = DateTime.Now;

            // Act
            Saving actual = Saving.Create(expectedId, expectedHouseholdId, expectedSavingTypeId,
                                          expectedName, expectedDescription, expectedAmount, expectedDate);

            // Assert
            Assert.IsTrue(actual != null);
            Assert.IsTrue(actual.Events != null);
            Assert.IsTrue(actual.Events.Count == 1);
            var events = actual.FlushUncommitedEvents();

            Assert.IsTrue(events != null);
            Assert.IsTrue(events.Length == 1);
            Assert.IsTrue(events[0] is SavingCreatedEvent);
            SavingCreatedEvent @event = events[0] as SavingCreatedEvent;

            Assert.IsTrue(@event.EntityId == expectedId);
            Assert.IsTrue(@event.HouseholdId == expectedHouseholdId);
            Assert.IsTrue(@event.SavingTypeId == expectedSavingTypeId);
            Assert.IsTrue(@event.Description == expectedDescription);
            Assert.IsTrue(@event.Name == expectedName);
            Assert.IsTrue(@event.Date == expectedDate);
        }
Beispiel #2
0
        public void ShouldModifyModel()
        {
            // Arrange
            Guid     expectedId           = Guid.NewGuid();
            Guid     expectedHouseholdId  = Guid.NewGuid();
            Guid     expectedSavingTypeId = Guid.NewGuid();
            string   expectedName         = "ModifiedName";
            string   expectedDescription  = "ModifiedDescription";
            decimal  expectedAmount       = 0.12m;
            DateTime expectedDate         = DateTime.Now.AddDays(1);

            // Act
            Saving actual = Saving.Create(expectedId, expectedHouseholdId, Guid.NewGuid(),
                                          "Name", "Description", 100.12M, DateTime.Now);

            actual.Modify(expectedSavingTypeId, expectedName, expectedDescription, expectedAmount,
                          expectedDate, 1);

            // Assert
            Assert.IsTrue(actual.Id == expectedId);
            Assert.IsTrue(actual.Name == expectedName);
            Assert.IsTrue(actual.Description == expectedDescription);
            Assert.IsTrue(actual.Date == expectedDate);
            Assert.IsTrue(actual.Amount == expectedAmount);
            Assert.IsTrue(actual.SavingTypeId == expectedSavingTypeId);
            Assert.IsTrue(!string.IsNullOrEmpty(actual.SearchValue));
        }
Beispiel #3
0
        public void ShouldCreateNewModel()
        {
            // Arrange
            Guid     expectedId           = Guid.NewGuid();
            Guid     expectedHouseholdId  = Guid.NewGuid();
            Guid     expectedSavingTypeId = Guid.NewGuid();
            string   expectedName         = "Name";
            string   expectedDescription  = "Description";
            decimal  expectedAmount       = 102.12m;
            DateTime expectedDate         = DateTime.Now;

            // Act
            Saving actual = Saving.Create(expectedId, expectedHouseholdId, expectedSavingTypeId,
                                          expectedName, expectedDescription, expectedAmount, expectedDate);

            // Assert
            Assert.IsTrue(actual != null);
            Assert.IsTrue(actual.Id == expectedId);
            Assert.IsTrue(actual.HouseholdId == expectedHouseholdId);
            Assert.IsTrue(actual.SavingTypeId == expectedSavingTypeId);
            Assert.IsTrue(actual.Name == expectedName);
            Assert.IsTrue(actual.Description == expectedDescription);
            Assert.IsTrue(actual.Amount == expectedAmount);
            Assert.IsTrue(actual.Date == expectedDate);
            Assert.IsTrue(!string.IsNullOrEmpty(actual.SearchValue));
        }
Beispiel #4
0
        public void ShouldHaveModifiedEvent()
        {
            // Arrange
            Guid     expectedId           = Guid.NewGuid();
            Guid     expectedSavingTypeId = Guid.NewGuid();
            string   expectedName         = "ModifiedName";
            string   expectedDescription  = "ModifiedDescription";
            decimal  expectedAmount       = 0.12m;
            DateTime expectedDate         = DateTime.Now.AddDays(1);

            // Act
            Saving actual = Saving.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(),
                                          "Name", "Description", 100.12M, DateTime.Now);

            actual.FlushUncommitedEvents();
            actual.Modify(expectedSavingTypeId, expectedName, expectedDescription, expectedAmount,
                          expectedDate, 1);

            // Assert
            Assert.IsTrue(actual.Events != null);
            Assert.IsTrue(actual.Events.Count == 1);
            var events = actual.FlushUncommitedEvents();

            Assert.IsTrue(events != null);
            Assert.IsTrue(events.Length == 1);
            Assert.IsTrue(events[0] is SavingModifiedEvent);
            SavingModifiedEvent @event = events[0] as SavingModifiedEvent;

            Assert.IsTrue(@event.EntityId == expectedId);
            Assert.IsTrue(@event.SavingTypeId == expectedSavingTypeId);
            Assert.IsTrue(@event.Amount == expectedAmount);
            Assert.IsTrue(@event.Description == expectedDescription);
            Assert.IsTrue(@event.Name == expectedName);
            Assert.IsTrue(@event.Date == expectedDate);
        }
        public async Task HandleAsync(CreateSavingCommand message, CancellationToken token = default(CancellationToken))
        {
            var saving = Saving.Create(Guid.NewGuid(), message.HouseholdId, message.SavingTypeId, message.Name,
                                       message.Description, message.Amount, message.Date);

            _savings.Add(saving);
            await _savings.SaveChangesAsync(token);
        }
Beispiel #6
0
        public void ShouldHaveDeletedEvent()
        {
            // Arrange
            Guid expectedId = Guid.NewGuid();

            // Act
            Saving actual = Saving.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(),
                                          "Name", "Description", 100.12M, DateTime.Now);

            actual.FlushUncommitedEvents();
            actual.Delete();

            // Assert
            Assert.IsTrue(actual.Events != null);
            Assert.IsTrue(actual.Events.Count == 1);
            var events = actual.FlushUncommitedEvents();

            Assert.IsTrue(events != null);
            Assert.IsTrue(events.Length == 1);
            Assert.IsTrue(events[0] is SavingDeletedEvent);
            SavingDeletedEvent @event = events[0] as SavingDeletedEvent;

            Assert.IsTrue(@event.EntityId == expectedId);
        }
Beispiel #7
0
        public async Task ShouldModifyExisting()
        {
            // Arrange
            Guid   expectedId   = Guid.NewGuid();
            string expectedName = "Modified Name";
            Saving entity       = Saving.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(), "Name", "Description",
                                                0.12m, DateTime.Now);
            var repository = new Mock <ISavingRepository>();

            repository.Setup(
                e => e.GetByIdAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(entity);
            ModifySavingCommand cmd =
                new ModifySavingCommand(expectedId, Guid.NewGuid(), expectedName, "Description",
                                        0.12m, DateTime.Now, 1);

            SavingCommandHandler actual = new SavingCommandHandler(repository.Object);

            // Act
            await actual.HandleAsync(cmd);

            // Assert
            Assert.IsTrue(entity.Id == expectedId);
            Assert.IsTrue(entity.Name == expectedName);
        }