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; IQuoteTweetService service = testServer.Host.Services.GetService(typeof(IQuoteTweetService)) as IQuoteTweetService; var model = new ApiQuoteTweetServerRequestModel(); model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, TimeSpan.Parse("02:00:00")); CreateResponse <ApiQuoteTweetServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.QuoteTweetDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiQuoteTweetServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
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 ApiQuoteTweetServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IQuoteTweetService service = testServer.Host.Services.GetService(typeof(IQuoteTweetService)) as IQuoteTweetService; ApiQuoteTweetServerResponseModel model = await service.Get(1); ApiQuoteTweetClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, TimeSpan.Parse("02:00:00")); UpdateResponse <ApiQuoteTweetClientResponseModel> updateResponse = await client.QuoteTweetUpdateAsync(model.QuoteTweetId, request); context.Entry(context.Set <QuoteTweet>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.QuoteTweetId.Should().Be(1); context.Set <QuoteTweet>().ToList()[0].Content.Should().Be("B"); context.Set <QuoteTweet>().ToList()[0].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <QuoteTweet>().ToList()[0].RetweeterUserId.Should().Be(1); context.Set <QuoteTweet>().ToList()[0].SourceTweetId.Should().Be(1); context.Set <QuoteTweet>().ToList()[0].Time.Should().Be(TimeSpan.Parse("02:00:00")); updateResponse.Record.QuoteTweetId.Should().Be(1); updateResponse.Record.Content.Should().Be("B"); updateResponse.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.RetweeterUserId.Should().Be(1); updateResponse.Record.SourceTweetId.Should().Be(1); updateResponse.Record.Time.Should().Be(TimeSpan.Parse("02:00:00")); }