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; IPostLinkService service = testServer.Host.Services.GetService(typeof(IPostLinkService)) as IPostLinkService; var model = new ApiPostLinkServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, 1); CreateResponse <ApiPostLinkServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.PostLinkDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiPostLinkServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public void MapServerRequestToResponse() { var mapper = new ApiPostLinkServerModelMapper(); var model = new ApiPostLinkServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiPostLinkServerResponseModel response = mapper.MapServerRequestToResponse(1, model); response.Should().NotBeNull(); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.LinkTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RelatedPostId.Should().Be(1); }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <IPostLinkService, IPostLinkRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PostLink>(null)); var service = new PostLinkService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Object, mock.DALMapperMockFactory.DALPostLinkMapperMock); ApiPostLinkServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }