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; IStudentService service = testServer.Host.Services.GetService(typeof(IStudentService)) as IStudentService; var model = new ApiStudentServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1); CreateResponse <ApiStudentServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.StudentDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiStudentServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <IStudentService, IStudentRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Student>(null)); var service = new StudentService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.StudentModelValidatorMock.Object, mock.DALMapperMockFactory.DALStudentMapperMock, mock.DALMapperMockFactory.DALEventStudentMapperMock); ApiStudentServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public void MapServerRequestToResponse() { var mapper = new ApiStudentServerModelMapper(); var model = new ApiStudentServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", true, 1, "A", true, "A", "A", true, 1); ApiStudentServerResponseModel response = mapper.MapServerRequestToResponse(1, model); response.Should().NotBeNull(); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.EmailRemindersEnabled.Should().Be(true); response.FamilyId.Should().Be(1); response.FirstName.Should().Be("A"); response.IsAdult.Should().Be(true); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.SmsRemindersEnabled.Should().Be(true); response.UserId.Should().Be(1); }