示例#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 ApiSelfReferenceServerModelMapper();
            ApplicationDbContext  context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ISelfReferenceService service             = testServer.Host.Services.GetService(typeof(ISelfReferenceService)) as ISelfReferenceService;
            ApiSelfReferenceServerResponseModel model = await service.Get(1);

            ApiSelfReferenceClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(1, 1);

            UpdateResponse <ApiSelfReferenceClientResponseModel> updateResponse = await client.SelfReferenceUpdateAsync(model.Id, request);

            context.Entry(context.Set <SelfReference>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <SelfReference>().ToList()[0].SelfReferenceId.Should().Be(1);
            context.Set <SelfReference>().ToList()[0].SelfReferenceId2.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.SelfReferenceId.Should().Be(1);
            updateResponse.Record.SelfReferenceId2.Should().Be(1);
        }
示例#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;

            ISelfReferenceService service = testServer.Host.Services.GetService(typeof(ISelfReferenceService)) as ISelfReferenceService;
            var model = new ApiSelfReferenceServerRequestModel();

            model.SetProperties(1, 1);
            CreateResponse <ApiSelfReferenceServerResponseModel> createdResponse = await service.Create(model);

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

            ActionResponse deleteResult = await client.SelfReferenceDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }