Exemplo n.º 1
0
        public async Task UserExists_UserDoesNotExist_ReturnsFalse(int id, int numAccounts, string namePrefix, int startingId,
                                                                   int idIncrementFactor)
        {
            // Arrange
            // Setting up each dependency of ValidationService as a Mock
            Mock <IUserProfileService> mockProfileService = new Mock <IUserProfileService>();
            Mock <IUserAccountService> mockAccountService = new Mock <IUserAccountService>();

            List <WebUserAccountModel> userAccounts = new List <WebUserAccountModel>();

            // Test helper to assist in instantiating a list of WebUserAccountModels
            var testHelper = new BusinessLayerTestHelper();

            /* Parameters:
             * numAccounts: How many would you like to generate?
             * namePrefix: What would you like to be the common prefix before every attribute?
             * startingId: What number would you like id to start from?
             * idIncrementFactor: How many numbers would you like each subsequent id to skip by?
             */
            userAccounts = testHelper.PopulateListOfAccountModels(numAccounts, namePrefix, startingId, idIncrementFactor);

            // This function reads as: If GetAllUserAccounts is called, then return a list of userAccounts
            mockAccountService.Setup(x => x.GetAllUserAccounts()).Returns(Task.FromResult(userAccounts));

            // Finally, instantiate the actual class being tested and pass in the mock objects
            IValidationService validationService = new ValidationService(mockAccountService.Object, mockProfileService.Object);

            // Act
            // Call the function that is being tested
            var actualResult = await validationService.UserExists(id);

            // Assert
            // This unit test will pass if it returns false
            Assert.IsFalse(actualResult);
        }