コード例 #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 ApiTestAllFieldTypesNullableRequestModel();

            createModel.SetProperties(2, BitConverter.GetBytes(2), true, "B", DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), 2, 2, BitConverter.GetBytes(2), 2m, "B", "B", 2m, "B", 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2m, "B", TimeSpan.Parse("1"), BitConverter.GetBytes(2), 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), BitConverter.GetBytes(2), "B", "B");
            CreateResponse <ApiTestAllFieldTypesNullableResponseModel> createResult = await client.TestAllFieldTypesNullableCreateAsync(createModel);

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

            ApiTestAllFieldTypesNullableResponseModel getResponse = await client.TestAllFieldTypesNullableGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.TestAllFieldTypesNullableDeleteAsync(2);

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

            ApiTestAllFieldTypesNullableResponseModel verifyResponse = await client.TestAllFieldTypesNullableGetAsync(2);

            verifyResponse.Should().BeNull();
        }
コード例 #2
0
        public virtual ApiTestAllFieldTypesNullableResponseModel MapBOToModel(
            BOTestAllFieldTypesNullable boTestAllFieldTypesNullable)
        {
            var model = new ApiTestAllFieldTypesNullableResponseModel();

            model.SetProperties(boTestAllFieldTypesNullable.Id, boTestAllFieldTypesNullable.FieldBigInt, boTestAllFieldTypesNullable.FieldBinary, boTestAllFieldTypesNullable.FieldBit, boTestAllFieldTypesNullable.FieldChar, boTestAllFieldTypesNullable.FieldDate, boTestAllFieldTypesNullable.FieldDateTime, boTestAllFieldTypesNullable.FieldDateTime2, boTestAllFieldTypesNullable.FieldDateTimeOffset, boTestAllFieldTypesNullable.FieldDecimal, boTestAllFieldTypesNullable.FieldFloat, boTestAllFieldTypesNullable.FieldImage, boTestAllFieldTypesNullable.FieldMoney, boTestAllFieldTypesNullable.FieldNChar, boTestAllFieldTypesNullable.FieldNText, boTestAllFieldTypesNullable.FieldNumeric, boTestAllFieldTypesNullable.FieldNVarchar, boTestAllFieldTypesNullable.FieldReal, boTestAllFieldTypesNullable.FieldSmallDateTime, boTestAllFieldTypesNullable.FieldSmallInt, boTestAllFieldTypesNullable.FieldSmallMoney, boTestAllFieldTypesNullable.FieldText, boTestAllFieldTypesNullable.FieldTime, boTestAllFieldTypesNullable.FieldTimestamp, boTestAllFieldTypesNullable.FieldTinyInt, boTestAllFieldTypesNullable.FieldUniqueIdentifier, boTestAllFieldTypesNullable.FieldVarBinary, boTestAllFieldTypesNullable.FieldVarchar, boTestAllFieldTypesNullable.FieldXML);

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

            var client = new ApiClient(testServer.CreateClient());
            ApiTestAllFieldTypesNullableResponseModel response = await client.TestAllFieldTypesNullableGetAsync(1);

            response.Should().NotBeNull();
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiTestAllFieldTypesNullableResponseModel response = await this.TestAllFieldTypesNullableService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
コード例 #5
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <ITestAllFieldTypesNullableRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <TestAllFieldTypesNullable>(null));
            var service = new TestAllFieldTypesNullableService(mock.LoggerMock.Object,
                                                               mock.RepositoryMock.Object,
                                                               mock.ModelValidatorMockFactory.TestAllFieldTypesNullableModelValidatorMock.Object,
                                                               mock.BOLMapperMockFactory.BOLTestAllFieldTypesNullableMapperMock,
                                                               mock.DALMapperMockFactory.DALTestAllFieldTypesNullableMapperMock);

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

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

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

            ApiTestAllFieldTypesNullableResponseModel model = await client.TestAllFieldTypesNullableGetAsync(1);

            ApiTestAllFieldTypesNullableModelMapper mapper = new ApiTestAllFieldTypesNullableModelMapper();

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

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

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

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

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

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

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
コード例 #9
0
        public void MapBOToModel()
        {
            var mapper = new BOLTestAllFieldTypesNullableMapper();
            BOTestAllFieldTypesNullable bo = new BOTestAllFieldTypesNullable();

            bo.SetProperties(1, 1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1m, 1m, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("0"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A");
            ApiTestAllFieldTypesNullableResponseModel response = mapper.MapBOToModel(bo);

            response.FieldBigInt.Should().Be(1);
            response.FieldBinary.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.FieldBit.Should().Be(true);
            response.FieldChar.Should().Be("A");
            response.FieldDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FieldDateTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FieldDateTime2.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FieldDateTimeOffset.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.FieldDecimal.Should().Be(1m);
            response.FieldFloat.Should().Be(1m);
            response.FieldImage.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.FieldMoney.Should().Be(1m);
            response.FieldNChar.Should().Be("A");
            response.FieldNText.Should().Be("A");
            response.FieldNumeric.Should().Be(1m);
            response.FieldNVarchar.Should().Be("A");
            response.FieldReal.Should().Be(1m);
            response.FieldSmallDateTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FieldSmallInt.Should().Be(1);
            response.FieldSmallMoney.Should().Be(1m);
            response.FieldText.Should().Be("A");
            response.FieldTime.Should().Be(TimeSpan.Parse("0"));
            response.FieldTimestamp.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.FieldTinyInt.Should().Be(1);
            response.FieldUniqueIdentifier.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.FieldVarBinary.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.FieldVarchar.Should().Be("A");
            response.FieldXML.Should().Be("A");
            response.Id.Should().Be(1);
        }
コード例 #10
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTestAllFieldTypesNullableRequestModel> patch)
        {
            ApiTestAllFieldTypesNullableResponseModel record = await this.TestAllFieldTypesNullableService.Get(id);

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

                UpdateResponse <ApiTestAllFieldTypesNullableResponseModel> result = await this.TestAllFieldTypesNullableService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #11
0
		public async void TestGet()
		{
			ApiTestAllFieldTypesNullableResponseModel response = await this.Client.TestAllFieldTypesNullableGetAsync(1);

			response.Should().NotBeNull();
		}