Пример #1
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 ApiEventStatusServerModelMapper();
            ApplicationDbContext context            = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IEventStatusService  service            = testServer.Host.Services.GetService(typeof(IEventStatusService)) as IEventStatusService;
            ApiEventStatusServerResponseModel model = await service.Get(1);

            ApiEventStatusClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiEventStatusClientResponseModel> updateResponse = await client.EventStatusUpdateAsync(model.Id, request);

            context.Entry(context.Set <EventStatus>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <EventStatus>().ToList()[0].Name.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Name.Should().Be("B");
        }
Пример #2
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;

            IEventStatusService service = testServer.Host.Services.GetService(typeof(IEventStatusService)) as IEventStatusService;
            var model = new ApiEventStatusServerRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiEventStatusServerResponseModel> createdResponse = await service.Create(model);

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

            ActionResponse deleteResult = await client.EventStatusDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiEventStatusServerModelMapper();
            var model  = new ApiEventStatusServerResponseModel();

            model.SetProperties(1, "A");
            ApiEventStatusServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Name.Should().Be("A");
        }
Пример #4
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiEventStatusServerResponseModel response = await this.EventStatusService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Пример #5
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IEventStatusService, IEventStatusRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <EventStatus>(null));
            var service = new EventStatusService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Object,
                                                 mock.DALMapperMockFactory.DALEventStatusMapperMock,
                                                 mock.DALMapperMockFactory.DALEventMapperMock);

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

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

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiEventStatusServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiEventStatusServerResponseModel> >(mockResponse.Object));
            EventStatusController controller = new EventStatusController(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 ApiEventStatusServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiEventStatusServerRequestModel>()));
        }
        public async void All_Exists()
        {
            EventStatusControllerMockFacade mock = new EventStatusControllerMockFacade();
            var record  = new ApiEventStatusServerResponseModel();
            var records = new List <ApiEventStatusServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            EventStatusController controller = new EventStatusController(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 <ApiEventStatusServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Пример #8
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiEventStatusServerRequestModel> patch)
        {
            ApiEventStatusServerResponseModel record = await this.EventStatusService.Get(id);

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

                UpdateResponse <ApiEventStatusServerResponseModel> result = await this.EventStatusService.Update(id, model);

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