public void Create_ShouldSetProperties_WhenPassedValidValues() { // Arrange var firstName = "Darth"; var lastName = "Vader"; var dateOfBirth = new DateTime(2010, 5, 4); var addr1 = "400 E 200 S"; var addr2 = ""; var city = "Salt Lake City"; var state = "UT"; var postalCode = "84101"; var interestValues = new List <string> { "c#", "TypeScript", "npm", "cycling" }; var interests = interestValues.Select(i => Interest.Create(i)).ToList(); var picture = new byte[] { 31, 2, 7 }; // Act var person = Person.CreatePerson(firstName, lastName, dateOfBirth, interests, picture, addr1, addr2, city, state, postalCode); // Assert person.FirstName.Should().Be(firstName); person.LastName.Should().Be(lastName); person.DateOfBirth.Should().Be(dateOfBirth); person.Address1.Should().Be(addr1); person.Address2.Should().Be(addr2); person.City.Should().Be(city); person.State.Should().Be(state); person.PostalCode.Should().Be(postalCode); foreach (var interest in person.Interests) { interests.Should().Contain(i => i.Value == interest.Value); } person.Picture.Should().BeSameAs(picture); }
private void PreInit() { _mockInterestDTO = new InterestDTO() { Id = 3, InterestDescription = "mock", InterestName = "mock" }; _mockInterest = Interest.Create("mock", "mock").Value; _mockInterest.Id = 3; _interestsList = new List <Interest>() { Interest.Create("mock", "mock").Value, Interest.Create("mock", "mock").Value }; _interestDTOs = new List <InterestDTO>() { new InterestDTO() { Id = 1, InterestDescription = "mock", InterestName = "mock" }, new InterestDTO() { Id = 2, InterestDescription = "mock2", InterestName = "mock2" } }; }
public async Task SetUserInterestsAsync_Should_Return_Success_Result() { var interestIds = new int[] { 1, 2, 3 }; List <Interest> interests = new List <Interest>(); for (int i = 1; i <= 3; i++) { var t = Interest.Create("mock", "mock").Value; t.Id = i; interests.Add(t); } var userRepositoryMock = new Mock <IUserRepository>(); var userFactoryMock = new Mock <IUserFactory>(); var userIdentityProviderMock = new Mock <IIdentityProvider>(); var mediatorMock = new Mock <IMediator>(); var interestRepositoryMock = new Mock <IInterestRepository>(); interestRepositoryMock.Setup(x => x.GetInterestsByIds(interestIds)).ReturnsAsync(Result.Ok(interests as IReadOnlyList <Interest>)); var userDomainService = new UserDomainService(interestRepositoryMock.Object); userIdentityProviderMock.Setup(x => x.GetUser()).ReturnsAsync(Result.Ok(_user)); userRepositoryMock.Setup(x => x.SaveChangesAsync(It.IsAny <string>())).ReturnsAsync(Result.Ok()); UserService userService = new UserService(userRepositoryMock.Object, userFactoryMock.Object, userIdentityProviderMock.Object, mediatorMock.Object, userDomainService); var result = await userService.SetUserInterestsAsync(interestIds); result.IsSuccessed.Should().BeTrue(); }
public void Create_Interest_Should_Return_Failure_Result_If_InterestName_Or_InterestDescription_Is_Null_Or_Empty(string interestName, string interestDescription, string errorMessage) { var result = Interest.Create(interestName, interestDescription); result.IsSuccessed.Should().BeFalse(); result.GetErrorString().Should().Be(errorMessage); }
public void Create_ShouldValidateParameters() { // Arrange // Act // Assert Assert.Throws <ArgumentException>(() => Interest.Create("")); // Arrange // Act // Assert Assert.Throws <ArgumentException>(() => Interest.Create(null)); }
public void Update_Interest_Should_Return_Success_Result(string interestName, string interestDescription) { var mockInterest = Interest.Create(interestName, interestDescription); _testInterest.UpdateInterest(mockInterest.Value); _testInterest.InterestDescription.Should().Be(interestDescription); _testInterest.InterestName.Should().Be(interestName); }
public void Create_Interest_Should_Return_Success_Result(string interestName, string interestDescription) { var result = Interest.Create(interestName, interestDescription); result.IsSuccessed.Should().BeTrue(); result.Value.InterestDescription.Should().Be(interestDescription); result.Value.InterestName.Should().Be(interestName); }
private void PreInit() { //_interestsList = new List<Interest>() { // new Interest() {Id = 1, InterestDescription = "mock", InterestName = "mock" }, // new Interest() {Id = 2, InterestDescription = "mock2", InterestName = "mock2" } //}; _interestsList.Add(Interest.Create("mock", "mock").Value); _interestsList.Add(Interest.Create("mock2", "mock2").Value); }
public void Create_ShouldSetProperties_WhenPassedValidValues() { // Arrange var interestText = "c#"; // Act var interest = Interest.Create(interestText); // Assert interest.Value.Should().Be(interestText); }
public static List <Interest> GetInterests() { var interests = new List <Interest>(); for (int i = 1; i <= 10; i++) { var interestResult = Interest.Create("Interest" + i, "Interest Description " + i); interests.Add(interestResult.Value); } return(interests); }
public void Update_Interest_Should_Return_Failure_Result(string interestName, string interestDescription) { try { var mockInterest = Interest.Create(interestName, interestDescription); _testInterest.UpdateInterest(mockInterest.Value); } catch (Exception ex) { ex.Message.Should().Be(Interest.Interest_Should_Not_Be_Empty); } }
private void CreateInterestsAndUserInterests(out List <Interest> interests, out List <UserInterest> userInterests, int numberOfInterests) { interests = new List <Interest>(); userInterests = new List <UserInterest>(); for (int i = 1; i <= numberOfInterests; i++) { var interest = Interest.Create("test", "test").Value; interest.Id = i; var userInterestResult = UserInterest.Create(i); interests.Add(interest); userInterests.Add(userInterestResult.Value); } }
public async Task <Result> InsertInterest(CreateInterestDTO createInterestDTO) { if (createInterestDTO == null) { return(Result.Fail(Constants.InterestErrorMessages.Interest_Should_Not_Be_Empty)); } var interestResult = Interest.Create(createInterestDTO.InterestName, createInterestDTO.InterestDescription); if (!interestResult.IsSuccessed) { return(Result.Fail(interestResult.GetErrorString())); } _interestRepository.Create(interestResult.Value); return(await _interestRepository.SaveChangesAsync(InterestErrorMessages.Error_Occured_While_Inserting_Interest)); }
private void CreateInterestsAndUserInterests(out List <Interest> interests, out List <UserInterest> userInterests, int[] interestIds) { interests = new List <Interest>(); userInterests = new List <UserInterest>(); if (interestIds == null) { return; } foreach (var i in interestIds) { var interest = Interest.Create("test", "test").Value; interest.Id = i; var userInterestResult = UserInterest.Create(i); interests.Add(interest); userInterests.Add(userInterestResult.Value); } }
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); }
public async Task <Result> UpdateInterest(InterestDTO interestDTO) { if (interestDTO == null) { return(Result.Fail(Constants.InterestErrorMessages.Interest_Should_Not_Be_Empty)); } var interest = Interest.Create(interestDTO.InterestName, interestDTO.InterestDescription); if (!interest.IsSuccessed) { return(Result.Fail(interest.GetErrorString())); } var actualInterest = await _interestRepository.GetInterestById(interestDTO.Id); if (!actualInterest.IsSuccessed) { return(Result.Fail(actualInterest.GetErrorString())); } actualInterest.Value.UpdateInterest(interest.Value); _interestRepository.Update(actualInterest.Value); return(await _interestRepository.SaveChangesAsync(InterestErrorMessages.Error_Occured_While_Updating_Interest)); }
public Person SavePerson(string firstName, string lastName, DateTime dateOfBirth, List <string> interestsValues, byte[] picture, string addr1, string addr2, string city, string state, string postalCode) { if (interestsValues == null) { interestsValues = new List <string>(); } // get all the interests that already exist in the repository var interestsInRepo = _interestRepository.GetByValues(interestsValues).ToList(); // get just the interst values var interestValuesInRepo = interestsInRepo.Select(i => i.Value).ToList(); // get all the interests provided that are NOT already in the repository var interestValuesNotInRepo = interestsValues.Where(interestValue => interestValuesInRepo.All(interestValueInRepo => interestValueInRepo != interestValue)); // construct the person's actual list of Interest objects var personsInterests = new List <Interest>(); personsInterests.AddRange(interestsInRepo); foreach (var interestValue in interestValuesNotInRepo) { var interest = _interestRepository.Add(Interest.Create(interestValue)); personsInterests.Add(interest); } var person = Person.CreatePerson(firstName, lastName, dateOfBirth, personsInterests, picture, addr1, addr2, city, state, postalCode); if (person != null) { _personRepository.Add(person); _personRepository.Save(); } return(person); }
public InterestTests() { _testInterest = Interest.Create("test", "test").Value; }