Пример #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;

            IStudioService service = testServer.Host.Services.GetService(typeof(IStudioService)) as IStudioService;
            var            model   = new ApiStudioServerRequestModel();

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

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

            ActionResponse deleteResult = await client.StudioDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
Пример #2
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiStudioServerResponseModel response = await this.StudioService.Get(id);

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

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Studio>(null));
            var service = new StudioService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.StudioModelValidatorMock.Object,
                                            mock.DALMapperMockFactory.DALStudioMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Пример #4
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiStudioServerModelMapper();
            var model  = new ApiStudioServerResponseModel();

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

            response.Should().NotBeNull();
            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.City.Should().Be("A");
            response.Name.Should().Be("A");
            response.Province.Should().Be("A");
            response.Website.Should().Be("A");
            response.Zip.Should().Be("A");
        }
Пример #5
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 ApiStudioServerModelMapper();
            ApplicationDbContext         context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IStudioService               service = testServer.Host.Services.GetService(typeof(IStudioService)) as IStudioService;
            ApiStudioServerResponseModel model   = await service.Get(1);

            ApiStudioClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B", "B", "B", "B", "B", "B", "B");

            UpdateResponse <ApiStudioClientResponseModel> updateResponse = await client.StudioUpdateAsync(model.Id, request);

            context.Entry(context.Set <Studio>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Studio>().ToList()[0].Address1.Should().Be("B");
            context.Set <Studio>().ToList()[0].Address2.Should().Be("B");
            context.Set <Studio>().ToList()[0].City.Should().Be("B");
            context.Set <Studio>().ToList()[0].Name.Should().Be("B");
            context.Set <Studio>().ToList()[0].Province.Should().Be("B");
            context.Set <Studio>().ToList()[0].Website.Should().Be("B");
            context.Set <Studio>().ToList()[0].Zip.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Address1.Should().Be("B");
            updateResponse.Record.Address2.Should().Be("B");
            updateResponse.Record.City.Should().Be("B");
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.Province.Should().Be("B");
            updateResponse.Record.Website.Should().Be("B");
            updateResponse.Record.Zip.Should().Be("B");
        }
Пример #6
0
        public async void Create_Errors()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiStudioServerRequestModel>()));
        }
Пример #7
0
        public async void All_Exists()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();
            var record  = new ApiStudioServerResponseModel();
            var records = new List <ApiStudioServerResponseModel>();

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

            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 <ApiStudioServerRequestModel> patch)
        {
            ApiStudioServerResponseModel record = await this.StudioService.Get(id);

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

                UpdateResponse <ApiStudioServerResponseModel> result = await this.StudioService.Update(id, model);

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