Ejemplo n.º 1
0
        public void Delete_VerifyDataAccess()
        {
            var fakeConfig         = MakeFakeConfig();
            var mockFileDataAccess = new MockIFileDataAccess <BlogUser>();
            var fileAdapter        = new BlogUserFileAdapter(fakeConfig, mockFileDataAccess);
            var param_entity       = new BlogUserFactory().Create();
            var stub_blogUser      = new BlogUserFactory().Create();

            stub_blogUser.UserId = Guid.Parse("55555555-5555-5555-5555-555555555555");
            var stub_list = new List <BlogUser> {
                param_entity, stub_blogUser
            };

            mockFileDataAccess.StubReadDatabase(stub_list);
            var expected_readDBfilePath      = fakeConfig[KeyChain.FileDataAccess_BlogUser_DatabasePath];
            var expected_overwriteDBfilePath = fakeConfig[KeyChain.FileDataAccess_BlogUser_DatabasePath];
            var expected_overwriteDB_newList = new List <BlogUser> {
                stub_blogUser
            };

            fileAdapter.Delete(param_entity);

            mockFileDataAccess.VerifyReadDatabase(expected_readDBfilePath);
            mockFileDataAccess.VerifyOverwriteDatabase(expected_overwriteDBfilePath, expected_overwriteDB_newList);
        }
Ejemplo n.º 2
0
        public void ValidateBlogUser_ValidBlogUser_Returns()
        {
            var validator      = new BlogUserValidator();
            var param_blogUser = new BlogUserFactory().Create();

            validator.ValidateBlogUser(param_blogUser);
        }
Ejemplo n.º 3
0
        public void ValidateBlogUser_PermissionsElementIsInvalid_ThrowsException(string invalidValue)
        {
            var validator      = new BlogUserValidator();
            var param_blogUser = new BlogUserFactory().Create();

            param_blogUser.Permissions.Add(invalidValue);
            Assert.Throws <ArgumentException>(
                () => validator.ValidateBlogUser(param_blogUser));
        }
Ejemplo n.º 4
0
        public void Add_Returns()
        {
            var fakeConfig         = MakeFakeConfig();
            var stubFileDataAccess = new StubIFileDataAccess <BlogUser>();
            var fileAdapter        = new BlogUserFileAdapter(fakeConfig, stubFileDataAccess);
            var param_entity       = new BlogUserFactory().Create();

            fileAdapter.Add(param_entity);
        }
Ejemplo n.º 5
0
        public void Add_ValidBlogUser_Returns()
        {
            var stubDataAccessAdapter = new StubIBlogUserDataAccessAdapter();
            var stubValidator         = new StubIBlogUserValidator();
            var repository            = new BlogUserRepository(stubDataAccessAdapter, stubValidator);
            var param_blogUser        = new BlogUserFactory().Create();

            repository.Add(param_blogUser);
        }
Ejemplo n.º 6
0
        public void ValidateBlogUser_UserNameIsInvalid_ThrowsException(string invalidValue)
        {
            var validator      = new BlogUserValidator();
            var param_blogUser = new BlogUserFactory().Create();

            param_blogUser.UserName = invalidValue;
            Assert.Throws <ArgumentException>(
                () => validator.ValidateBlogUser(param_blogUser));
        }
Ejemplo n.º 7
0
        public void ValidateBlogUser_PermissionsIsNull_ThrowsException()
        {
            var validator      = new BlogUserValidator();
            var param_blogUser = new BlogUserFactory().Create();

            param_blogUser.Permissions = null;
            Assert.Throws <ArgumentNullException>(
                () => validator.ValidateBlogUser(param_blogUser));
        }
Ejemplo n.º 8
0
        public void Edit_ValidBlogUser_VerifyValidator()
        {
            var stubDataAccessAdapter = new StubIBlogUserDataAccessAdapter();
            var mockValidator         = new MockIBlogUserValidator();
            var repository            = new BlogUserRepository(stubDataAccessAdapter, mockValidator);
            var param_blogUser        = new BlogUserFactory().Create();

            repository.Edit(param_blogUser);

            mockValidator.VerifyValidateBlogUser(param_blogUser);
        }
Ejemplo n.º 9
0
        public void Delete_ValidBlogUser_VerifyDataAccessAdapter()
        {
            var mockDataAccessAdapter = new MockIBlogUserDataAccessAdapter();
            var stubValidator         = new StubIBlogUserValidator();
            var repository            = new BlogUserRepository(mockDataAccessAdapter, stubValidator);
            var param_blogUser        = new BlogUserFactory().Create();

            repository.Delete(param_blogUser);

            mockDataAccessAdapter.VerifyDelete(param_blogUser);
        }
Ejemplo n.º 10
0
        public void GetById_ValidBlogUser_VerifyDataAccessAdapter()
        {
            var mockDataAccessAdapter = new MockIBlogUserDataAccessAdapter();
            var stubValidator         = new StubIBlogUserValidator();
            var repository            = new BlogUserRepository(mockDataAccessAdapter, stubValidator);
            var param_userId          = new BlogUserFactory().Create().UserId;

            repository.GetById(param_userId);

            mockDataAccessAdapter.VerifyGetById(param_userId);
        }
        public void Edit_Return()
        {
            var fakeConfig           = MakeFakeConfig();
            var stubWebApiDataAccess = new StubIWebApiDataAccess();
            var webApiAdapter        = new BlogUserWebApiAdapter(fakeConfig, stubWebApiDataAccess);
            var param_entity         = new BlogUserFactory().Create();

            stubWebApiDataAccess.StubSendRequest(MakeHttpResponseMessage(HttpStatusCode.OK));

            webApiAdapter.Edit(param_entity);
        }
Ejemplo n.º 12
0
        public void Add_VerifyDataAccess()
        {
            var fakeConfig         = MakeFakeConfig();
            var mockFileDataAccess = new MockIFileDataAccess <BlogUser>();
            var fileAdapter        = new BlogUserFileAdapter(fakeConfig, mockFileDataAccess);
            var param_entity       = new BlogUserFactory().Create();
            var expectedfilePath   = fakeConfig[KeyChain.FileDataAccess_BlogUser_DatabasePath];

            fileAdapter.Add(param_entity);

            mockFileDataAccess.VerifyWriteToDatabase(expectedfilePath, param_entity);
        }
        public void Edit_VerifySendRequestCalled()
        {
            var fakeConfig           = MakeFakeConfig();
            var mockWebApiDataAccess = new MockIWebApiDataAccess();
            var webApiAdapter        = new BlogUserWebApiAdapter(fakeConfig, mockWebApiDataAccess);
            var param_entity         = new BlogUserFactory().Create();

            mockWebApiDataAccess.StubSendRequest(MakeHttpResponseMessage(HttpStatusCode.OK));

            webApiAdapter.Edit(param_entity);

            mockWebApiDataAccess.VerifySendRequestCalled(1);
        }
        public void Add_Returns()
        {
            var fakeConfig = MakeFakeConfig();
            var stubSqlParameterBuilder = new StubISqlParameterBuilder();
            var stubSqlServerDataAccess = new StubISqlServerDataAccess();
            var sqlServerAdapter        = new BlogUserSqlServerAdapter(fakeConfig,
                                                                       stubSqlServerDataAccess, stubSqlParameterBuilder);
            var param_entity = new BlogUserFactory().Create();

            stubSqlServerDataAccess.StubExecuteNonQueryStoredProcedure(1);

            sqlServerAdapter.Add(param_entity);
        }
Ejemplo n.º 15
0
        public void GetById_ValidBlogUser_ReturnsExpectedBlogUser()
        {
            var stubDataAccessAdapter = new StubIBlogUserDataAccessAdapter();
            var stubValidator         = new StubIBlogUserValidator();
            var repository            = new BlogUserRepository(stubDataAccessAdapter, stubValidator);
            var expected = new BlogUserFactory().Create();

            stubDataAccessAdapter.StubGetById(expected);
            var param_userId = expected.UserId;

            var actual = repository.GetById(param_userId);

            Assert.Equal(expected, actual);
        }
        public void GetById_ListReturnedIsEmpty_ReturnsNullBlogUser()
        {
            var fakeConfig = MakeFakeConfig();
            var stubSqlParameterBuilder = new StubISqlParameterBuilder();
            var stubSqlServerDataAccess = new StubISqlServerDataAccess();
            var sqlServerAdapter        = new BlogUserSqlServerAdapter(fakeConfig,
                                                                       stubSqlServerDataAccess, stubSqlParameterBuilder);
            var param_id = new BlogUserFactory().Create().UserId;

            stubSqlServerDataAccess.StubExecuteReaderStoredProcedure(new List <BlogUser>());

            var returned_blogpost = sqlServerAdapter.GetById(param_id);

            Assert.Null(returned_blogpost);
        }
        public void Delete_VerifySqlServerDataAccess()
        {
            var fakeConfig = MakeFakeConfig();
            var stubSqlParameterBuilder = new StubISqlParameterBuilder();
            var mockSqlServerDataAccess = new MockISqlServerDataAccess();
            var sqlServerAdapter        = new BlogUserSqlServerAdapter(fakeConfig,
                                                                       mockSqlServerDataAccess, stubSqlParameterBuilder);
            var param_entity = new BlogUserFactory().Create();

            mockSqlServerDataAccess.StubExecuteNonQueryStoredProcedure(1);

            sqlServerAdapter.Delete(param_entity);

            mockSqlServerDataAccess.VerifyExecuteNonQueryStoredProcedureCalled(1);
        }
        public void GetById_ListReturnedIsEmpty_VerifySqlServerDataAccess()
        {
            var fakeConfig = MakeFakeConfig();
            var stubSqlParameterBuilder = new StubISqlParameterBuilder();
            var mockSqlServerDataAccess = new MockISqlServerDataAccess();
            var sqlServerAdapter        = new BlogUserSqlServerAdapter(fakeConfig,
                                                                       mockSqlServerDataAccess, stubSqlParameterBuilder);
            var param_id = new BlogUserFactory().Create().UserId;

            mockSqlServerDataAccess.StubExecuteReaderStoredProcedure(new List <BlogUser>());

            sqlServerAdapter.GetById(param_id);

            mockSqlServerDataAccess.VerifyExecuteReaderStoredProcedureCalled <BlogUser>(1);
        }
        public void GetById_ReturnsExpectedBlogUser()
        {
            var fakeConfig           = MakeFakeConfig();
            var stubWebApiDataAccess = new StubIWebApiDataAccess();
            var webApiAdapter        = new BlogUserWebApiAdapter(fakeConfig, stubWebApiDataAccess);
            var param_id             = new BlogUserFactory().Create().UserId;
            var expected             = new BlogUserFactory().Create();
            var stub_response        = MakeHttpResponseMessage(HttpStatusCode.OK);

            stub_response.Content = new StringContent(JsonConvert.SerializeObject(expected));
            stubWebApiDataAccess.StubSendRequest(stub_response);

            var actual = webApiAdapter.GetById(param_id);

            AssertBlogUserAreEqual(expected, actual);
        }
        public void GetById_VerifySendRequestCalled()
        {
            var fakeConfig            = MakeFakeConfig();
            var mockWebApiDataAccess  = new MockIWebApiDataAccess();
            var webApiAdapter         = new BlogUserWebApiAdapter(fakeConfig, mockWebApiDataAccess);
            var param_id              = new BlogUserFactory().Create().UserId;
            var stub_expectedBlogUser = new BlogUserFactory().Create();
            var stub_response         = MakeHttpResponseMessage(HttpStatusCode.OK);

            stub_response.Content = new StringContent(JsonConvert.SerializeObject(stub_expectedBlogUser));
            mockWebApiDataAccess.StubSendRequest(stub_response);

            webApiAdapter.GetById(param_id);

            mockWebApiDataAccess.VerifySendRequestCalled(1);
        }
Ejemplo n.º 21
0
        public void ListBlogUsers_VerifyBlogUserRepository()
        {
            var mockBlogUserRepo = new MockIBlogUserRepository();
            var interactor       = new ListBlogUsersInteractor(mockBlogUserRepo);
            var stub_BlogUser    = new BlogUserFactory().Create();
            var stub_listOfUsers = new List <BlogUser> {
                stub_BlogUser
            };

            mockBlogUserRepo.StubList(stub_listOfUsers);
            var expected      = MakeResponse(stub_listOfUsers, true);
            var param_request = MakeRequest(stub_BlogUser);

            var response = interactor.ListBlogUsers(param_request);

            mockBlogUserRepo.VerifyList();
        }
Ejemplo n.º 22
0
        public void Edit_Returns()
        {
            var fakeConfig         = MakeFakeConfig();
            var stubFileDataAccess = new StubIFileDataAccess <BlogUser>();
            var fileAdapter        = new BlogUserFileAdapter(fakeConfig, stubFileDataAccess);
            var param_entity       = new BlogUserFactory().Create();
            var stub_blogUser      = new BlogUserFactory().Create();

            stub_blogUser.UserId = Guid.Parse("55555555-5555-5555-5555-555555555555");
            var stub_list = new List <BlogUser> {
                param_entity, stub_blogUser
            };

            stubFileDataAccess.StubReadDatabase(stub_list);

            fileAdapter.Edit(param_entity);
        }
Ejemplo n.º 23
0
        public void List_VerifyFileDataAccess()
        {
            var fakeConfig         = MakeFakeConfig();
            var mockFileDataAccess = new MockIFileDataAccess <BlogUser>();
            var fileAdapter        = new BlogUserFileAdapter(fakeConfig, mockFileDataAccess);
            var stub_blogUser      = new BlogUserFactory().Create();
            var stub_list          = new List <BlogUser> {
                stub_blogUser
            };

            mockFileDataAccess.StubReadDatabase(stub_list);
            var expected_readDBfilePath = fakeConfig[KeyChain.FileDataAccess_BlogUser_DatabasePath];

            fileAdapter.List();

            mockFileDataAccess.VerifyReadDatabase(expected_readDBfilePath);
        }
Ejemplo n.º 24
0
        public void List_ReturnsExpectedList()
        {
            var fakeConfig         = MakeFakeConfig();
            var stubFileDataAccess = new StubIFileDataAccess <BlogUser>();
            var fileAdapter        = new BlogUserFileAdapter(fakeConfig, stubFileDataAccess);
            var stub_blogUser      = new BlogUserFactory().Create();
            var stub_list          = new List <BlogUser> {
                stub_blogUser
            };

            stubFileDataAccess.StubReadDatabase(stub_list);
            var expected = stub_list;

            var actual = fileAdapter.List();

            Assert.Equal(expected, actual);
        }
        public void List_VerifySendRequestCalled()
        {
            var fakeConfig           = MakeFakeConfig();
            var mockWebApiDataAccess = new MockIWebApiDataAccess();
            var webApiAdapter        = new BlogUserWebApiAdapter(fakeConfig, mockWebApiDataAccess);
            var stub_entity          = new BlogUserFactory().Create();
            var stub_list            = new List <BlogUser> {
                stub_entity
            };
            var stub_response = MakeHttpResponseMessage(HttpStatusCode.OK);

            stub_response.Content = new StringContent(JsonConvert.SerializeObject(stub_list));
            mockWebApiDataAccess.StubSendRequest(stub_response);

            webApiAdapter.List();

            mockWebApiDataAccess.VerifySendRequestCalled(1);
        }
Ejemplo n.º 26
0
        public void ListBlogUsers_ReturnsExpectedResponse()
        {
            var stubBlogUserRepo = new StubIBlogUserRepository();
            var interactor       = new ListBlogUsersInteractor(stubBlogUserRepo);
            var stub_BlogUser    = new BlogUserFactory().Create();
            var stub_listOfUsers = new List <BlogUser> {
                stub_BlogUser
            };

            stubBlogUserRepo.StubList(stub_listOfUsers);
            var expected      = MakeResponse(stub_listOfUsers, true);
            var param_request = MakeRequest(stub_BlogUser);

            var actual = interactor.ListBlogUsers(param_request);

            Assert.Equal(expected.RequestSuccessful, actual.RequestSuccessful);
            Assert.Equal(expected.ListOfUsers, actual.ListOfUsers);
        }
        public void GetBlogPost_VerifyBlogUserRepository()
        {
            var stubBlogPostRepo = new StubIBlogPostRepository();
            var mockBlogUserRepo = new MockIBlogUserRepository();
            var interactor       = new GetBlogPostInteractor(stubBlogPostRepo, mockBlogUserRepo);
            var stub_BlogPost    = new BlogPostFactory().Create();
            var stub_BlogUser    = new BlogUserFactory().Create();

            stub_BlogPost.AuthorId = stub_BlogUser.UserId;
            stubBlogPostRepo.StubGetById(stub_BlogPost);
            mockBlogUserRepo.StubGetById(stub_BlogUser);
            var expected      = MakeResponse(stub_BlogPost, stub_BlogUser, true);
            var param_request = MakeRequest(stub_BlogPost);

            var response = interactor.GetBlogPost(param_request);

            mockBlogUserRepo.VerifyGetById(stub_BlogUser.UserId);
        }
Ejemplo n.º 28
0
        public void LoginUser_UserNameExists_ReturnsExpectedLoginUserResponse()
        {
            var stubBlogUserRepo = new StubIBlogUserRepository();
            var interactor       = new LoginUserInteractor(stubBlogUserRepo);
            var stub_blogUser    = new BlogUserFactory().Create();
            var stub_list        = new List <BlogUser> {
                stub_blogUser
            };

            stubBlogUserRepo.StubList(stub_list);
            var expected      = MakeResponse(stub_blogUser, true);
            var param_request = MakeRequest(stub_blogUser.UserName);

            var actual = interactor.LoginUser(param_request);

            Assert.Equal(expected.SystemLoginSuccessful, actual.SystemLoginSuccessful);
            Assert.Equal(expected.User, actual.User);
        }
        public void RegisterUser_UserNameIsNotAvailable_VerifyRepository()
        {
            var mockBlogUserRepo = new MockIBlogUserRepository();
            var interactor       = new RegisterUserInteractor(mockBlogUserRepo);
            var stub_blogUser    = new BlogUserFactory().Create();

            mockBlogUserRepo.StubList(new List <BlogUser> {
                stub_blogUser
            });
            var param_request = new RegisterUserRequest {
                UserName = stub_blogUser.UserName
            };

            var actual = interactor.RegisterUser(param_request);

            mockBlogUserRepo.VerifyList();
            mockBlogUserRepo.VerifyAddNeverCalled();
        }
        public void List_ReturnsExpectedList()
        {
            var fakeConfig           = MakeFakeConfig();
            var stubWebApiDataAccess = new StubIWebApiDataAccess();
            var webApiAdapter        = new BlogUserWebApiAdapter(fakeConfig, stubWebApiDataAccess);
            var stub_entity          = new BlogUserFactory().Create();
            var expected             = new List <BlogUser> {
                stub_entity
            };
            var stub_response = MakeHttpResponseMessage(HttpStatusCode.OK);

            stub_response.Content = new StringContent(JsonConvert.SerializeObject(expected));
            stubWebApiDataAccess.StubSendRequest(stub_response);

            var actual = webApiAdapter.List();

            AssertListOfBlogUserAreEqual(expected, actual);
        }