public void SavePerson_ShouldGracefullyHandleANullInterestList() { // Arrange var mockPersonRepository = new Mock <IPersonRepository>(); var mockInterestRepository = new Mock <IInterestRepository>(); var personCommandsService = new PersonCommandsService(mockPersonRepository.Object, mockInterestRepository.Object); // Act // Assert Assert.DoesNotThrow(() => personCommandsService.SavePerson("Dark", "Vader", new DateTime(1977, 5, 4), null, null, null, null, null, null, null)); }
public void SavePerson_ShouldCallRepostoryAddAndSave_WhenGivenAValidOfPersonInformation() { // Arrange var interests = new List <string> { "C#", "The Sith", "The Dark Side of the Force" }; var mockInterestRepository = new Mock <IInterestRepository>(); mockInterestRepository .Setup(r => r.Add(It.IsAny <Interest>())) .Verifiable(); mockInterestRepository .Setup(r => r.Add(It.IsAny <Interest>())) .Verifiable(); mockInterestRepository .Setup(r => r.Add(It.IsAny <Interest>())) .Verifiable(); var mockPersonRepository = new Mock <IPersonRepository>(); mockPersonRepository .Setup(r => r.Add(It.IsAny <Person>())).Verifiable(); mockPersonRepository .Setup(r => r.Save()).Verifiable(); var personCommandsService = new PersonCommandsService(mockPersonRepository.Object, mockInterestRepository.Object); var firstName = "Darth"; var lastName = "Vader"; var dateOfBirth = new DateTime(2015, 5, 4); // Act var person = personCommandsService.SavePerson(firstName, lastName, dateOfBirth, interests, null, null, null, null, null, null); // Assert mockInterestRepository.VerifyAll(); mockPersonRepository.VerifyAll(); person.Should().NotBeNull(); person.FirstName.Should().Be(firstName); person.LastName.Should().Be(lastName); person.DateOfBirth.Should().Be(dateOfBirth); person.Interests.Count.Should().Be(interests.Count); }
public void Constructor_ShouldInitializeProperties_WhenPassedAValidPersonEntity() { // Arrange var firstName = "Darth"; var lastName = "Vader"; var dateOfBirth = new DateTime(1976, 5, 4); var interestValues = new List <string> { "Luke Skywalker", "The Force", "The Sith" }; var interests = interestValues.Select(iv => Interest.Create(iv)).ToList(); var address1 = "TIE Figher"; var address2 = "Death Star"; var city = "The Death Star"; var state = "The Galactic Empire"; var postalCode = "Everywhere"; var picture = new byte[] { 23, 53, 12 }; var mockPersonRepository = new Mock <IPersonRepository>(); var mockInterestRepository = new Mock <IInterestRepository>(); mockInterestRepository.Setup(r => r.GetByValues(It.IsAny <List <string> >())).Returns(interests); var personCommandService = new PersonCommandsService(mockPersonRepository.Object, mockInterestRepository.Object); var person = personCommandService.SavePerson(firstName, lastName, dateOfBirth, interestValues, picture, address1, address2, city, state, postalCode); // Act var personDto = new PersonDto(person); // Assert personDto.PersonId.Should().Be(0); personDto.FirstName.Should().Be(firstName); personDto.LastName.Should().Be(lastName); personDto.Age.Should().Be(PersonDto.CalculateAge(dateOfBirth)); personDto.Address1.Should().Be(address1); personDto.Address2.Should().Be(address2); personDto.City.Should().Be(city); personDto.State.Should().Be(state); personDto.PostalCode.Should().Be(postalCode); personDto.Interests.Should().BeEquivalentTo(interestValues); personDto.Picture.Should().BeEquivalentTo(picture); }
public void SavePerson_ShouldEnsureDuplicateInterestsAreNotSaved_WhenANewPersonIsSaved() { // Arrange var mockInterestRepository = new MockInterestRepository(); mockInterestRepository.Add(Interest.Create("C#")); mockInterestRepository.Add(Interest.Create("Linq")); //mockInterestRepository.Add(Interest.Create("C#")); var mockPersonRepository = new Mock <IPersonRepository>(); var personCommandsService = new PersonCommandsService(mockPersonRepository.Object, mockInterestRepository); var interests = new List <string> { "C#", "The Sith", "The Dark Side of the Force" }; var numOfInterestsBeforeSave = mockInterestRepository.InterestList.Count; // Act personCommandsService.SavePerson("Darth", "Vader", new DateTime(1977, 5, 4), interests, new byte[0], null, null, null, null, null); // Assert mockInterestRepository.InterestList.Count.Should().Be(numOfInterestsBeforeSave + 2); }