public void QueryByIdGetNotNull() { // Arrange Guid guid = Guid.NewGuid(); var contextMock = new Mock <DashboardDbContext>(); var dbsetMock = new Mock <DbSet <Portal> >(); contextMock.Setup(x => x.Portals).Returns(dbsetMock.Object); contextMock.Setup(foo => foo.Portals.FindAsync(It.IsAny <Guid>())).ReturnsAsync( new Portal { URL = "http://www.google.com" } ); var serviceMock = new Mock <IQueryPortalService>(); serviceMock.Setup(x => x.QueryByPortalAsync(It.IsAny <Portal>())).ReturnsAsync( new PortalResponse { Status = 245 } ); var notificationMock = new Mock <INotificationsService>(); IQueryPortalService queryService = new QueryPortalService(contextMock.Object, new HttpClient(), notificationMock.Object); // Act // var response = await queryService.QueryByIdAsync(guid); // var portalResponse = response.portalResponse; // var resp = await serviceMock.Object.QueryByIdAsync(guid); // Assert // Assert.NotNull(portalResponse); // Assert.IsType<PortalResponse>(portalResponse); // contextMock.Verify(s => s.Portals.FindAsync(It.IsAny<Guid>()), Times.Once()); //cant mock //serviceMock.Verify(s => s.QueryByPortalAsync(It.IsAny<Portal>()), Times.Once()); }
public void QueryByIdNullGetNull() { // Arrange Guid guid = Guid.NewGuid(); var contextMock = new Mock <DashboardDbContext>(); var dbsetMock = new Mock <DbSet <Portal> >(); contextMock.Setup(x => x.Portals).Returns(dbsetMock.Object); contextMock.Setup(foo => foo.Portals.FindAsync(It.IsAny <Guid>())).Returns(null); var notificationMock = new Mock <INotificationsService>(); IQueryPortalService queryService = new QueryPortalService(contextMock.Object, new HttpClient(), notificationMock.Object); // Act // var response = await queryService.QueryByIdAsync(guid); // var portalResponse = response.portalResponse; // Assert // Assert.Null(portalResponse); // contextMock.Verify(s => s.Portals.FindAsync(It.IsAny<Guid>()), Times.Once()); }