Example #1
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            ICustomerCommunicationService service = testServer.Host.Services.GetService(typeof(ICustomerCommunicationService)) as ICustomerCommunicationService;
            var model = new ApiCustomerCommunicationServerRequestModel();

            model.SetProperties(1, DateTime.Parse("1/1/1988 12:00:00 AM"), 1, "B");
            CreateResponse <ApiCustomerCommunicationServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.CustomerCommunicationDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiCustomerCommunicationServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Example #2
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiCustomerCommunicationServerResponseModel response = await this.CustomerCommunicationService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Example #3
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiCustomerCommunicationServerModelMapper();
            var model  = new ApiCustomerCommunicationServerResponseModel();

            model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A");
            ApiCustomerCommunicationServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.CustomerId.Should().Be(1);
            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.EmployeeId.Should().Be(1);
            response.Notes.Should().Be("A");
        }
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <ICustomerCommunicationService, ICustomerCommunicationRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <CustomerCommunication>(null));
            var service = new CustomerCommunicationService(mock.LoggerMock.Object,
                                                           mock.MediatorMock.Object,
                                                           mock.RepositoryMock.Object,
                                                           mock.ModelValidatorMockFactory.CustomerCommunicationModelValidatorMock.Object,
                                                           mock.DALMapperMockFactory.DALCustomerCommunicationMapperMock);

            ApiCustomerCommunicationServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Example #5
0
        public async void Create_Errors()
        {
            CustomerCommunicationControllerMockFacade mock = new CustomerCommunicationControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiCustomerCommunicationServerResponseModel> >(null as ApiCustomerCommunicationServerResponseModel);
            var mockRecord   = new ApiCustomerCommunicationServerResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCustomerCommunicationServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCustomerCommunicationServerResponseModel> >(mockResponse.Object));
            CustomerCommunicationController controller = new CustomerCommunicationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiCustomerCommunicationServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCustomerCommunicationServerRequestModel>()));
        }
Example #6
0
        public async void All_Exists()
        {
            CustomerCommunicationControllerMockFacade mock = new CustomerCommunicationControllerMockFacade();
            var record  = new ApiCustomerCommunicationServerResponseModel();
            var records = new List <ApiCustomerCommunicationServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            CustomerCommunicationController controller = new CustomerCommunicationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0, string.Empty);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiCustomerCommunicationServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Example #7
0
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiCustomerCommunicationServerModelMapper();
            ApplicationDbContext          context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ICustomerCommunicationService service             = testServer.Host.Services.GetService(typeof(ICustomerCommunicationService)) as ICustomerCommunicationService;
            ApiCustomerCommunicationServerResponseModel model = await service.Get(1);

            ApiCustomerCommunicationClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(1, DateTime.Parse("1/1/1988 12:00:00 AM"), 1, "B");

            UpdateResponse <ApiCustomerCommunicationClientResponseModel> updateResponse = await client.CustomerCommunicationUpdateAsync(model.Id, request);

            context.Entry(context.Set <CustomerCommunication>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <CustomerCommunication>().ToList()[0].CustomerId.Should().Be(1);
            context.Set <CustomerCommunication>().ToList()[0].DateCreated.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <CustomerCommunication>().ToList()[0].EmployeeId.Should().Be(1);
            context.Set <CustomerCommunication>().ToList()[0].Notes.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.CustomerId.Should().Be(1);
            updateResponse.Record.DateCreated.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.EmployeeId.Should().Be(1);
            updateResponse.Record.Notes.Should().Be("B");
        }
Example #8
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiCustomerCommunicationServerRequestModel> patch)
        {
            ApiCustomerCommunicationServerResponseModel record = await this.CustomerCommunicationService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiCustomerCommunicationServerRequestModel model = await this.PatchModel(id, patch) as ApiCustomerCommunicationServerRequestModel;

                UpdateResponse <ApiCustomerCommunicationServerResponseModel> result = await this.CustomerCommunicationService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }