public void InsertClientAsync_ThrowsExceptionInternalError()
        {
            var fixture       = new ClientServiceFixture();
            var errorInfo     = fixture.faker.CreateFakerErrorInfo(HttpStatusCode.InternalServerError);
            var errorInfoList = new List <ErrorInfo> {
                errorInfo
            };
            var exception = new Exception("Error");

            exception.HResult = 0;

            fixture.mockRepository.Setup(m => m.Insert(It.IsAny <Client>())).Throws(exception);
            fixture.messages.InternalError            = errorInfo.message;
            fixture.messages.InternalErrorDescription = errorInfo.details;

            var viewModel = fixture.faker.CreateFakerClientViewModel();

            var receivedResult = fixture.SUT.InsertClientAsync(viewModel).GetAwaiter().GetResult();
            var expectedResult = new ResponseModel <Client>(true, errorInfoList);

            receivedResult.Should().BeEquivalentTo(expectedResult, opt => opt
                                                   .Using <ErrorInfo>(ei => ei.Subject.Should()
                                                                      .BeEquivalentTo(ei.Expectation, o => o.Excluding(e => e.errorId)))
                                                   .WhenTypeIs <ErrorInfo>());
        }
Example #2
0
        public void FixtureConstructor_OK()
        {
            var fixture = new ClientServiceFixture();

            fixture.Should().NotBeNull();
            fixture.mockLogger.Should().NotBeNull();
            fixture.mockRepository.Should().NotBeNull();
            fixture.SUT.Should().NotBeNull();
            fixture.faker.Should().NotBeNull();
        }
        public void GetAllClientsAsync_ReturnCorrectlyOnSuccess()
        {
            var fixture = new ClientServiceFixture();
            var clients = fixture.faker.CreateFakerClientList();

            fixture.mockRepository.Setup(m => m.GetAll()).ReturnsAsync(clients);

            var receivedResult = fixture.SUT.GetAllClientsAsync().GetAwaiter().GetResult();
            var expectedResult = new ResponseModel <List <Client> >(clients);

            receivedResult.Should().BeEquivalentTo(expectedResult);
        }
        public void GetClientAsync_ReturnCorrectlyOnSuccess()
        {
            var fixture   = new ClientServiceFixture();
            var viewModel = fixture.faker.CreateFakerClientViewModel();
            var client    = new Client(viewModel);

            fixture.mockRepository.Setup(m => m.GetOne(It.IsAny <Guid>())).ReturnsAsync(client);

            var receivedResult = fixture.SUT.GetClientAsync(Guid.NewGuid()).GetAwaiter().GetResult();
            var expectedResult = new ResponseModel <Client>(new Client(viewModel));

            receivedResult.Should().BeEquivalentTo(expectedResult, opt => opt.Excluding(c => c.data.ClientId));
        }
        public void GetAllClientsAsync_ReturnClientsNotFound()
        {
            var fixture       = new ClientServiceFixture();
            var errorInfo     = fixture.faker.CreateFakerErrorInfo(HttpStatusCode.NotFound);
            var errorInfoList = new List <ErrorInfo> {
                errorInfo
            };
            var clients = new List <Client>();

            fixture.mockRepository.Setup(m => m.GetAll()).ReturnsAsync(clients);
            fixture.messages.ClientNotFound            = errorInfo.message;
            fixture.messages.ClientNotFoundDescription = errorInfo.details;

            var receivedResult = fixture.SUT.GetAllClientsAsync().GetAwaiter().GetResult();
            var expectedResult = new ResponseModel <List <Client> >(true, errorInfoList);

            receivedResult.Should().BeEquivalentTo(expectedResult, opt => opt
                                                   .Using <ErrorInfo>(ei => ei.Subject.Should()
                                                                      .BeEquivalentTo(ei.Expectation, o => o.Excluding(e => e.errorId)))
                                                   .WhenTypeIs <ErrorInfo>());
        }
        public void InsertClientAsync_ReturnNoClientChanged()
        {
            var fixture       = new ClientServiceFixture();
            var errorInfo     = fixture.faker.CreateFakerErrorInfo(HttpStatusCode.Conflict);
            var errorInfoList = new List <ErrorInfo> {
                errorInfo
            };

            fixture.mockRepository.Setup(m => m.Insert(It.IsAny <Client>())).ReturnsAsync(0);
            fixture.messages.NoClientChanged            = errorInfo.message;
            fixture.messages.NoClientChangedDescription = errorInfo.details;

            var viewModel = fixture.faker.CreateFakerClientViewModel();

            var receivedResult = fixture.SUT.InsertClientAsync(viewModel).GetAwaiter().GetResult();
            var expectedResult = new ResponseModel <Client>(true, errorInfoList);

            receivedResult.Should().BeEquivalentTo(expectedResult, opt => opt
                                                   .Using <ErrorInfo>(ei => ei.Subject.Should()
                                                                      .BeEquivalentTo(ei.Expectation, o => o.Excluding(e => e.errorId)))
                                                   .WhenTypeIs <ErrorInfo>());
        }
        public void UpdateClientAsync_ReturnClientNotFound()
        {
            var fixture       = new ClientServiceFixture();
            var errorInfo     = fixture.faker.CreateFakerErrorInfo(HttpStatusCode.NotFound);
            var errorInfoList = new List <ErrorInfo> {
                errorInfo
            };
            var viewModel = fixture.faker.CreateFakerClientViewModel();
            var client    = new Client(viewModel);

            fixture.mockRepository.Setup(m => m.Update(It.IsAny <Client>())).ReturnsAsync(0);
            fixture.mockRepository.Setup(m => m.GetOne(It.IsAny <Guid>())).ReturnsAsync(value: null);
            fixture.messages.ClientNotFound            = errorInfo.message;
            fixture.messages.ClientNotFoundDescription = errorInfo.details;

            var receivedResult = fixture.SUT.UpdateClientAsync(Guid.NewGuid(), viewModel).GetAwaiter().GetResult();
            var expectedResult = new ResponseModel <Client>(true, errorInfoList);

            receivedResult.Should().BeEquivalentTo(expectedResult, opt => opt
                                                   .Using <ErrorInfo>(ei => ei.Subject.Should()
                                                                      .BeEquivalentTo(ei.Expectation, o => o.Excluding(e => e.errorId)))
                                                   .WhenTypeIs <ErrorInfo>());
        }