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 ApiMessengerClientRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 1, TimeSpan.Parse("02:00:00"), 1, 1); CreateResponse <ApiMessengerClientResponseModel> result = await client.MessengerCreateAsync(model); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Messenger>().ToList()[1].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Messenger>().ToList()[1].FromUserId.Should().Be(2); context.Set <Messenger>().ToList()[1].MessageId.Should().Be(1); context.Set <Messenger>().ToList()[1].Time.Should().Be(TimeSpan.Parse("02:00:00")); context.Set <Messenger>().ToList()[1].ToUserId.Should().Be(1); context.Set <Messenger>().ToList()[1].UserId.Should().Be(1); result.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); result.Record.FromUserId.Should().Be(2); result.Record.MessageId.Should().Be(1); result.Record.Time.Should().Be(TimeSpan.Parse("02:00:00")); result.Record.ToUserId.Should().Be(1); result.Record.UserId.Should().Be(1); }
public virtual ApiMessengerClientRequestModel MapServerResponseToClientRequest( ApiMessengerServerResponseModel response) { var request = new ApiMessengerClientRequestModel(); request.SetProperties( response.Date, response.FromUserId, response.MessageId, response.Time, response.ToUserId, response.UserId); return(request); }
public void MapClientRequestToResponse() { var mapper = new ApiMessengerModelMapper(); var model = new ApiMessengerClientRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, TimeSpan.Parse("01:00:00"), 1, 1); ApiMessengerClientResponseModel response = mapper.MapClientRequestToResponse(1, model); response.Should().NotBeNull(); response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FromUserId.Should().Be(1); response.MessageId.Should().Be(1); response.Time.Should().Be(TimeSpan.Parse("01:00:00")); response.ToUserId.Should().Be(1); response.UserId.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 ApiMessengerServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IMessengerService service = testServer.Host.Services.GetService(typeof(IMessengerService)) as IMessengerService; ApiMessengerServerResponseModel model = await service.Get(1); ApiMessengerClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 1, TimeSpan.Parse("02:00:00"), 1, 1); UpdateResponse <ApiMessengerClientResponseModel> updateResponse = await client.MessengerUpdateAsync(model.Id, request); context.Entry(context.Set <Messenger>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <Messenger>().ToList()[0].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Messenger>().ToList()[0].FromUserId.Should().Be(2); context.Set <Messenger>().ToList()[0].MessageId.Should().Be(1); context.Set <Messenger>().ToList()[0].Time.Should().Be(TimeSpan.Parse("02:00:00")); context.Set <Messenger>().ToList()[0].ToUserId.Should().Be(1); context.Set <Messenger>().ToList()[0].UserId.Should().Be(1); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.FromUserId.Should().Be(2); updateResponse.Record.MessageId.Should().Be(1); updateResponse.Record.Time.Should().Be(TimeSpan.Parse("02:00:00")); updateResponse.Record.ToUserId.Should().Be(1); updateResponse.Record.UserId.Should().Be(1); }