コード例 #1
0
        public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

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

            var createModel = new ApiTenantRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiTenantResponseModel> createResult = await client.TenantCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiTenantResponseModel getResponse = await client.TenantGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.TenantDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiTenantResponseModel verifyResponse = await client.TenantGetAsync(2);

            verifyResponse.Should().BeNull();
        }
コード例 #2
0
        public virtual ApiTenantResponseModel MapBOToModel(
            BOTenant boTenant)
        {
            var model = new ApiTenantResponseModel();

            model.SetProperties(boTenant.Id, boTenant.DataVersion, boTenant.JSON, boTenant.Name, boTenant.ProjectIds, boTenant.TenantTags);

            return(model);
        }
コード例 #3
0
        public virtual ApiTenantResponseModel MapBOToModel(
            BOTenant boTenant)
        {
            var model = new ApiTenantResponseModel();

            model.SetProperties(boTenant.Id, boTenant.Name);

            return(model);
        }
コード例 #4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiTenantModelMapper();
            var model  = new ApiTenantResponseModel();

            model.SetProperties(1, "A");
            ApiTenantRequestModel response = mapper.MapResponseToRequest(model);

            response.Name.Should().Be("A");
        }
コード例 #5
0
        public void MapBOToModel()
        {
            var      mapper = new BOLTenantMapper();
            BOTenant bo     = new BOTenant();

            bo.SetProperties(1, "A");
            ApiTenantResponseModel response = mapper.MapBOToModel(bo);

            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
        }
コード例 #6
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiTenantResponseModel response = await client.TenantGetAsync(1);

            response.Should().NotBeNull();
        }
コード例 #7
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiTenantResponseModel response = await this.TenantService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
コード例 #8
0
        public async virtual Task <IActionResult> ByName(string name)
        {
            ApiTenantResponseModel response = await this.TenantService.ByName(name);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
コード例 #9
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiTenantModelMapper();
            var model  = new ApiTenantResponseModel();

            model.SetProperties("A", BitConverter.GetBytes(1), "A", "A", "A", "A");
            ApiTenantRequestModel response = mapper.MapResponseToRequest(model);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectIds.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
コード例 #10
0
        public void MapBOToModel()
        {
            var      mapper = new BOLTenantMapper();
            BOTenant bo     = new BOTenant();

            bo.SetProperties("A", BitConverter.GetBytes(1), "A", "A", "A", "A");
            ApiTenantResponseModel response = mapper.MapBOToModel(bo);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectIds.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
コード例 #11
0
		public async void Get_null_record()
		{
			var mock = new ServiceMockFacade<ITenantRepository>();
			mock.RepositoryMock.Setup(x => x.Get(It.IsAny<string>())).Returns(Task.FromResult<Tenant>(null));
			var service = new TenantService(mock.LoggerMock.Object,
			                                mock.RepositoryMock.Object,
			                                mock.ModelValidatorMockFactory.TenantModelValidatorMock.Object,
			                                mock.BOLMapperMockFactory.BOLTenantMapperMock,
			                                mock.DALMapperMockFactory.DALTenantMapperMock);

			ApiTenantResponseModel response = await service.Get(default(string));

			response.Should().BeNull();
			mock.RepositoryMock.Verify(x => x.Get(It.IsAny<string>()));
		}
コード例 #12
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

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

            ApiTenantResponseModel model = await client.TenantGetAsync(1);

            ApiTenantModelMapper mapper = new ApiTenantModelMapper();

            UpdateResponse <ApiTenantResponseModel> updateResponse = await client.TenantUpdateAsync(model.Id, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
コード例 #13
0
        public async void Create_Errors()
        {
            TenantControllerMockFacade mock = new TenantControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiTenantResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiTenantResponseModel();

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTenantRequestModel>()));
        }
コード例 #14
0
        public async void All_Exists()
        {
            TenantControllerMockFacade mock = new TenantControllerMockFacade();
            var record  = new ApiTenantResponseModel();
            var records = new List <ApiTenantResponseModel>();

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

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
コード例 #15
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTenantRequestModel> patch)
        {
            ApiTenantResponseModel record = await this.TenantService.Get(id);

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

                UpdateResponse <ApiTenantResponseModel> result = await this.TenantService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #16
0
        public async void TestGet()
        {
            ApiTenantResponseModel response = await this.Client.TenantGetAsync("A");

            response.Should().NotBeNull();
        }