Exemple #1
0
        public async void CreateInLibraryRelationship_Test()
        {
            // Arrange
            var newBook = CreateBook();
            await _bookRepository.AddOrUpdateAsync(newBook);

            var newPerson = CreatePerson();
            await _personRepository.AddPersonAsync(newPerson);

            var inLibrary = new Relationships.InLibrary();

            // Act
            await _bookRepository.CreateInLibraryRelationshipAsync(newBook, newPerson, inLibrary);

            var returnedPerson = (await _bookRepository.GetInLibraryPersonRelationshipAsync(newBook, inLibrary))
                                 .ToList().FirstOrDefault();

            // Assert
            Assert.True(newPerson.Name == returnedPerson.Name);

            // Clean up
            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook, newPerson, inLibrary);

            await _bookRepository.DeleteBookAsync(newBook);

            await _personRepository.DeletePersonAsync(newPerson);
        }
Exemple #2
0
        public async Task<IActionResult> AddPersonAsync(Person person)
        {
            Console.WriteLine($"person {person.Name}" );

            if (!CheckEmailAddress(person.Email))
            {
                return Ok("Email in incorrect format");
            }

            // Make sure Email Address Does not below to anyone else
            var inUse = await _personRepository.GetPersonByEmailAsync(person.Email);
            if (inUse != null)
            {
                return Ok("Email Address already in Use, select distinct email address");
            }

            person.ChangePassword = "******";

            var success = await _personRepository.AddPersonAsync(person);

            if (success)
            {
                person.Token = _tokenClass.CreateToken();
                person.TokenDate = DateTime.UtcNow.ToString();
                await UpdatePersonAsync(person);

                var callBackUrl = String.Empty;
            
                try
                {
                    callBackUrl = Url.Action("ConfirmEmail", "Email");
                    Console.WriteLine($"We got here with a url value of {callBackUrl}");
                } 
                catch (Exception ex)
                { 
                    Console.WriteLine($"Exception occured when generating link for email {ex}");
                }

                var confirmationLink = _emailHelper.ConfirmationLinkBody(person, callBackUrl);
                bool emailResponse = await _emailHelper.SendEmail(person.Name, person.Email, confirmationLink, 
                    _emailHelper.ConfirmationLinkSubject());

             
                if (emailResponse)
                {
                    Console.WriteLine($"Valid Email Address {person.Email}");
                }
                else
                {
                    Console.WriteLine($"Invalid Email Address {person.Email}");
                    return Ok($"Invalid Email Address {person.Email}");
                }
            }

            Console.WriteLine($"success {success}" );
            return Ok(success);
        }
        public async Task AddPersonAsync_GivenPerson_ShouldReturnPersonCorrectly()
        {
            // Arrange
            using (PeopleSearchDbContext testContext = GetTestContext())
            {
                Person expected = TestData.TestPerson1();


                PersonRepository repository = new PersonRepository(testContext);

                // Act
                Person actual = await repository.AddPersonAsync(expected);

                // Assert
                ModelComparisonHelper.AssertPeopleAreEqual(expected, actual);
            }
        }
        public async Task AddPersonAsync_GivenNullPerson_ShouldNotAdd()
        {
            // Arrange
            using (PeopleSearchDbContext testContext = GetTestContext())
            {
                PersonRepository repository = new PersonRepository(testContext);

                int expected = 0;

                // Act
                await repository.AddPersonAsync(null);

                // Assert
                int actual = await testContext.People.CountAsync();

                Assert.AreEqual(expected, actual);
            }
        }
        public async Task AddPersonAsync_GivenPersonDoesNotExist_ShouldAdd()
        {
            // Arrange
            using (PeopleSearchDbContext testContext = GetTestContext())
            {
                Person        added    = TestData.TestPerson1();
                List <Person> expected = new List <Person> {
                    added
                };


                PersonRepository repository = new PersonRepository(testContext);

                // Act
                await repository.AddPersonAsync(added);

                // Assert
                List <Person> actual = await testContext.People.ToListAsync();

                ModelComparisonHelper.AssertPersonListsAreEqual(expected, actual);
            }
        }
        public async void PopularLibrary_Test()
        {
            //Arrange
            var newPerson = CreatePerson();
            await _personRepository.AddPersonAsync(newPerson);

            var newPerson2 = CreatePerson();
            await _personRepository.AddPersonAsync(newPerson2);

            var newPerson3 = CreatePerson();
            await _personRepository.AddPersonAsync(newPerson3);

            var newBook = CreateBook();
            await _bookRepository.AddOrUpdateAsync(newBook);

            var newBook2 = CreateBook();
            await _bookRepository.AddOrUpdateAsync(newBook2);

            var newBook3 = CreateBook();
            await _bookRepository.AddOrUpdateAsync(newBook3);

            var inLibrary = new Relationships.InLibrary();

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook, newPerson, inLibrary);

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook2, newPerson, inLibrary);

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook3, newPerson, inLibrary);

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook2, newPerson2, inLibrary);

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook3, newPerson2, inLibrary);

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook3, newPerson3, inLibrary);

            //Act
            var query = (await _recommendationRepository.PopularLibrarys());

            //Assert
            Assert.NotNull(query);
            //Cleanup
            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook, newPerson, inLibrary);

            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook2, newPerson, inLibrary);

            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook3, newPerson, inLibrary);

            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook2, newPerson2, inLibrary);

            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook3, newPerson2, inLibrary);

            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook3, newPerson3, inLibrary);

            await _bookRepository.DeleteBookAsync(newBook);

            await _bookRepository.DeleteBookAsync(newBook2);

            await _bookRepository.DeleteBookAsync(newBook3);

            await _personRepository.DeletePersonAsync(newPerson);

            await _personRepository.DeletePersonAsync(newPerson2);

            await _personRepository.DeletePersonAsync(newPerson3);
        }
        public async void GetPeopleAsync_Test()
        {
            var person1 = CreatePerson();
            var person2 = CreatePerson();
            await _personRepository.AddPersonAsync(person1);

            await _personRepository.AddPersonAsync(person2);

            var people = await _personRepository.GetAllPeopleAsync();

            Assert.True(people != null);

            // Clean up
            await _personRepository.DeletePersonAsync(person1);

            await _personRepository.DeletePersonAsync(person2);
        }
Exemple #8
0
 public async Task <int> AddPersonAsync(Person person)
 {
     return(await _repository.AddPersonAsync(person));
 }
        async Task CanAddPerson()
        {
            Person person = await _personRespository.AddPersonAsync(new Person(), new CancellationToken());

            Assert.NotNull(person);
            Assert.NotEqual(default, person.Created);