public void GetAllNotificationsByEmployer_ReturnsAllNotificationsByEmployerFromService()
        {
            // Assert
            var person          = new PersonBuilder().WithId(1).Build();
            var employer        = new EmployerBuilder().WithId(1).Build();
            var job             = new JobBuilder().WithId(1).Build();
            var personViewModel = new PersonViewModelBuilder().WithId(1).Build();

            var notifications = new List <Notification>
            {
                new NotificationBuilder().WithId(1).WithEmployer(employer).WithPerson(person).WithJob(job).Build(),
            };

            var notificationViewModels = new List <NotificationViewModel>
            {
                new NotificationViewModelBuilder().WithId(1).WithPerson(personViewModel).WithJob(job).Build(),
            };

            _notificationServiceMock.Setup(n => n.GetAllNotificationsByEmployerId(It.IsAny <long>()))
            .ReturnsAsync(notifications);

            _mapperMock.Setup(m => m.Map <List <NotificationViewModel> >(notifications))
            .Returns(notificationViewModels);

            // Act
            var okResult = _controller.GetAllNotificationsByEmployer(1).Result as OkObjectResult;

            // Assert
            Assert.That(okResult, Is.Not.Null);
            Assert.That(okResult.Value, Is.EqualTo(notificationViewModels));
            _mapperMock.Verify(m => m.Map <List <NotificationViewModel> >(notifications), Times.Once);
        }
Ejemplo n.º 2
0
        public void GetPerson_ReturnsPersonFromService()
        {
            // Arrange
            var person          = new PersonBuilder().WithId(1).WithFirstName("Siebe").WithLastName("Corstjens").Build();
            var personViewModel = new PersonViewModelBuilder().WithId(1).WithName("Siebe Corstjens").Build();

            _personServiceMock.Setup(p => p.GetPerson(It.IsAny <long>())).ReturnsAsync(person);

            _mapperMock.Setup(m => m.Map <PersonViewModel>(person)).Returns(personViewModel);

            // Act
            var okResult = _controller.GetPerson(1).Result as OkObjectResult;

            // Assert
            Assert.That(okResult, Is.Not.Null);
            Assert.That(okResult.Value, Is.EqualTo(personViewModel));
            _mapperMock.Verify(m => m.Map <PersonViewModel>(person), Times.Once);
        }
Ejemplo n.º 3
0
 public void SetUp()
 {
     _personViewModelBuilder = new PersonViewModelBuilder();
 }
        public void Edit_POST_GivenModelStateIsValid_ShouldRedirectToIndex()
        {
            //---------------Set up test pack-------------------
            var existingPerson = PersonBuilder.BuildRandom();
            var personViewModel = new PersonViewModelBuilder().WithRandomProps().Build();

            var personRepository = Substitute.For<IPersonRepository>();
            personRepository.GetById(personViewModel.Id).Returns(existingPerson);
            var mappingEngine = _container.Resolve<IMappingEngine>();

            var personController = CreatePersonController()
                .WithPersonRepository(personRepository)
                .WithMappingEngine(mappingEngine)
                .Build();

            //---------------Assert Precondition----------------
            Assert.IsTrue(personController.ModelState.IsValid);
            //---------------Execute Test ----------------------
            var result = personController.Edit(personViewModel) as RedirectToRouteResult;
            //---------------Test Result -----------------------
            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        public void Edit_POST_GivenModelStateIsValid_ShouldCallUpdateFromOrderRepo()
        {
            //---------------Set up test pack-------------------
            var existingPerson = PersonBuilder.BuildRandom();
            var personViewModel = new PersonViewModelBuilder().WithRandomProps().Build();

            var personRepository = Substitute.For<IPersonRepository>();
            personRepository.GetById(personViewModel.Id).Returns(existingPerson);
            var mappingEngine = _container.Resolve<IMappingEngine>();

            var personController = CreatePersonController()
                .WithPersonRepository(personRepository)
                .WithMappingEngine(mappingEngine)
                .Build();

            //---------------Assert Precondition----------------
            Assert.IsTrue(personController.ModelState.IsValid);
            //---------------Execute Test ----------------------
            var result = personController.Edit(personViewModel);
            //---------------Test Result -----------------------
            personRepository.Received().Update(existingPerson, Arg.Any<Person>());
        }
        public void Edit_POST_GivenModelStateIsValid_ShouldCallMappingEngine()
        {
            //---------------Set up test pack-------------------
            var person = new PersonBuilder().WithRandomProps().Build();
            var personViewModel = new PersonViewModelBuilder().WithRandomProps().Build();
            var personRepository = Substitute.For<IPersonRepository>();
            personRepository.GetById(person.PersonId).Returns(person);
            var mappingEngine = Substitute.For<IMappingEngine>();
            var personController = CreatePersonController()
                .WithPersonRepository(personRepository)
                .WithMappingEngine(mappingEngine)
                .Build();

            //---------------Assert Precondition----------------
            Assert.IsTrue(personController.ModelState.IsValid);
            //---------------Execute Test ----------------------
            var result = personController.Edit(personViewModel);
            //---------------Test Result -----------------------
            mappingEngine.Received().Map<PersonViewModel, Person>(personViewModel);
        }
        public void Edit_POST_GivenModelStateIsValid_ShouldCallGetByIdFromOrderRepo()
        {
            //---------------Set up test pack-------------------
            var personViewModel = new PersonViewModelBuilder().WithRandomProps().Build();
            var personRepository = Substitute.For<IPersonRepository>();
            var personController = CreatePersonController()
                .WithPersonRepository(personRepository)
                .Build();

            //---------------Assert Precondition----------------
            Assert.IsTrue(personController.ModelState.IsValid);
            //---------------Execute Test ----------------------
            var result = personController.Edit(personViewModel);
            //---------------Test Result -----------------------
            personRepository.Received().GetById(personViewModel.Id);
        }