public virtual async void TestCreate() { 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; var model = new ApiVoteClientRequestModel(); model.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, 1); CreateResponse <ApiVoteClientResponseModel> result = await client.VoteCreateAsync(model); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Vote>().ToList()[1].BountyAmount.Should().Be(2); context.Set <Vote>().ToList()[1].CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Vote>().ToList()[1].PostId.Should().Be(1); context.Set <Vote>().ToList()[1].UserId.Should().Be(1); context.Set <Vote>().ToList()[1].VoteTypeId.Should().Be(1); result.Record.BountyAmount.Should().Be(2); result.Record.CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); result.Record.PostId.Should().Be(1); result.Record.UserId.Should().Be(1); result.Record.VoteTypeId.Should().Be(1); }
public virtual ApiVoteClientRequestModel MapServerResponseToClientRequest( ApiVoteServerResponseModel response) { var request = new ApiVoteClientRequestModel(); request.SetProperties( response.BountyAmount, response.CreationDate, response.PostId, response.UserId, response.VoteTypeId); return(request); }
public void MapClientRequestToResponse() { var mapper = new ApiVoteModelMapper(); var model = new ApiVoteClientRequestModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiVoteClientResponseModel response = mapper.MapClientRequestToResponse(1, model); response.Should().NotBeNull(); response.BountyAmount.Should().Be(1); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PostId.Should().Be(1); response.UserId.Should().Be(1); response.VoteTypeId.Should().Be(1); }
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 ApiVoteServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IVoteService service = testServer.Host.Services.GetService(typeof(IVoteService)) as IVoteService; ApiVoteServerResponseModel model = await service.Get(1); ApiVoteClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, 1); UpdateResponse <ApiVoteClientResponseModel> updateResponse = await client.VoteUpdateAsync(model.Id, request); context.Entry(context.Set <Vote>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <Vote>().ToList()[0].BountyAmount.Should().Be(2); context.Set <Vote>().ToList()[0].CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Vote>().ToList()[0].PostId.Should().Be(1); context.Set <Vote>().ToList()[0].UserId.Should().Be(1); context.Set <Vote>().ToList()[0].VoteTypeId.Should().Be(1); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.BountyAmount.Should().Be(2); updateResponse.Record.CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.PostId.Should().Be(1); updateResponse.Record.UserId.Should().Be(1); updateResponse.Record.VoteTypeId.Should().Be(1); }