public async Task HandlingCreatePersonCommand_ShouldAddPersonToRepository()
        {
            // Act
            var result = await _dut.Handle(_command, default);

            // Assert
            Assert.AreEqual(0, result.Errors.Count);
            Assert.AreEqual(Unit.Value, result.Data);
            Assert.AreEqual(_oid, _personAdded.Oid);
            Assert.AreEqual(FirstName, _personAdded.FirstName);
            Assert.AreEqual(LastName, _personAdded.LastName);
        }
        public void CreatePersonHandler_Returns_Ajax_Command_Result()
        {
            // Setup
            var handler = new CreatePersonCommandHandler(mockDb.Object);

            // Act
            var result = handler.Handle(new CreatePersonCommand());

            // Verify
            Assert.IsInstanceOf <Task <AjaxCommandResult> >(result);
        }
        public void CreatePersonHandler_Calls_SaveChanges()
        {
            // Setup
            var handler = new CreatePersonCommandHandler(mockDb.Object);

            // Act
            handler.Handle(new CreatePersonCommand());

            // Verify
            mockDb.Verify(x => x.SaveChangesAsync(), Times.Once);
        }
示例#4
0
        public async Task Handle_InValidPerson_ShouldReturnValidationErrors()
        {
            var handler = new CreatePersonCommandHandler(_mapper, _mockPersonRepository.Object, _mockLogger.Object, _cacheService.Object);

            var newPerson = new CreatePersonCommand
            {
                Firstname = "Test Firstname"
            };

            CreatePersonCommandResponse response = await handler.Handle(newPerson, CancellationToken.None);

            response.ValidationErrors.Count.ShouldBeGreaterThan(0);
        }
示例#5
0
        public void Handle_GivenValidRequest_ShouldRaiseCustomerCreatedNotification()
        {
            // Arrange
            var mediatorMock = new Mock <IMediator>();
            var sut          = new CreatePersonCommandHandler(this._context);
            var fullname     = "asad";
            var group        = 1;
            // Act
            var result = sut.Handle(new CreatePersonCommand {
                Fullname = fullname, GroupId = group
            }, CancellationToken.None);

            // Assert
            Assert.Equal(4, result.Result);
        }
        public void CreatePersonHandler_Returns_Id_In_Response()
        {
            // Setup
            var handler = new CreatePersonCommandHandler(mockDb.Object);

            var expectedResult = new AjaxCommandResult(true);

            // Act
            var result = handler.Handle(new CreatePersonCommand
            {
                Firstname = "test",
                Surname   = "test2"
            }).Result;

            // Assert
            result.Should().BeEquivalentTo(expectedResult);
        }
示例#7
0
        public async Task Handle_FutureDateOfBirth_ShouldReturnValidationErrors()
        {
            var handler = new CreatePersonCommandHandler(_mapper, _mockPersonRepository.Object, _mockLogger.Object, _cacheService.Object);

            var newPerson = new CreatePersonCommand
            {
                Firstname    = "Test Firstname",
                Surname      = "Test Surname",
                Gender       = "Male",
                EmailAddress = "Test Email",
                PhoneNumber  = "Test Phonenumber",
                DateOfBirth  = DateTime.Now.AddDays(1)
            };

            CreatePersonCommandResponse response = await handler.Handle(newPerson, CancellationToken.None);

            response.ValidationErrors.Count.ShouldBeGreaterThan(0);
        }
示例#8
0
        public async Task Handle_ValidPerson_AddedToPersonsRepo()
        {
            var handler = new CreatePersonCommandHandler(_mapper, _mockPersonRepository.Object, _mockLogger.Object, _cacheService.Object);

            var newPerson = new CreatePersonCommand
            {
                Firstname    = "Test Firstname",
                Surname      = "Test Surname",
                Gender       = "Male",
                EmailAddress = "Test Email",
                PhoneNumber  = "Test Phonenumber",
                DateOfBirth  = DateTime.Now.AddYears(-30)
            };

            await handler.Handle(newPerson, CancellationToken.None);

            var allPersons = await _mockPersonRepository.Object.ListAllAsync();

            allPersons.Count.ShouldBe(3);
        }
示例#9
0
        public async Task Create_New_Person()
        {
            using (var context = GetContextWithData())
            {
                var handler = new CreatePersonCommandHandler(context);
                var command = new CreatePersonCommand
                {
                    Name    = "Name",
                    Email   = "*****@*****.**",
                    IsAdmin = false
                };

                await handler.Handle(command, CancellationToken.None);

                var person = await context.Persons.SingleOrDefaultAsync(c => c.Name == command.Name);

                Assert.Equal(command.Name, person.Name);
                Assert.Equal(command.Email, person.Email);
                Assert.Equal(command.IsAdmin, person.IsAdmin);
            }
        }