public async void TestExamplePing( [Frozen(Matching.ImplementedInterfaces)] PingRepository pingRepo, PingModel dummyPing, PingController sut) { SetupExpectedPingInDatabase(dummyPing.Ping); // because Gen with test connection is used, a config with the connection string // will be injected into the controller making it "live" var actual = await sut.Ping(dummyPing).Unwrap <PongModel>(); Assert.Equal(dummyPing.Ping, actual.Pong); }
public async void CanGetPing( [Frozen] Mock <IReceiveAsync <PingModel, PongModel> > pingrepo, PingModel ping, PongModel pong, PingController sut) { pingrepo.Setup(x => x.GetDataAsync(ping)).ReturnsAsync(pong); var result = await sut.Ping(ping).Unwrap(); var actual = await result.Unwrap <PongModel>(); Assert.Equal(pong, actual); }
public async Task <IHttpActionResult> Ping(PingModel ping) { try { var result = await _pingRepository.GetDataAsync(ping); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async void CanGetPingFail( [Frozen] Mock <IReceiveAsync <PingModel, PongModel> > pingrepo, PingModel dummyPing, Exception expected, PingController sut) { pingrepo.Setup(x => x.GetDataAsync(It.IsAny <PingModel>())).ThrowsAsync(expected); var result = await sut.Ping(dummyPing).Unwrap(); Assert.False(result.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); var actual = await result.Unwrap <HttpError>(); Assert.Equal(expected.Message, actual.Message); }