public void MapServerResponseToRequest() { var mapper = new ApiVoteServerModelMapper(); var model = new ApiVoteServerResponseModel(); model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiVoteServerRequestModel response = mapper.MapServerResponseToRequest(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 void CreatePatch() { var mapper = new ApiVoteServerModelMapper(); var model = new ApiVoteServerRequestModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); JsonPatchDocument <ApiVoteServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiVoteServerRequestModel(); patch.ApplyTo(response); 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); }