public void CanGetWithSync() { var apiEntity1 = new ApiSample { Id = Guid.NewGuid() }; var apiEntity2 = new ApiSample { Id = Guid.NewGuid() }; var sampleController = new SampleController(service); var apiSync = sampleController.Get(-1); Assert.AreEqual(0, apiSync.LastSync); Assert.AreEqual(0, apiSync.Data.Length); Assert.AreEqual(0, apiSync.DeletedData.Length); service.Write(apiEntity1); apiSync = sampleController.Get(apiSync.LastSync); Assert.AreEqual(1, apiSync.LastSync); Assert.AreEqual(1, apiSync.Data.Length); Assert.AreEqual(apiEntity1.Id, apiSync.Data[0].Id); Assert.AreEqual(0, apiSync.DeletedData.Length); service.Write(apiEntity2); service.Remove(apiEntity1); apiSync = sampleController.Get(apiSync.LastSync); Assert.AreEqual(3, apiSync.LastSync); Assert.AreEqual(1, apiSync.Data.Length); Assert.AreEqual(apiEntity2.Id, apiSync.Data[0].Id); Assert.AreEqual(1, apiSync.DeletedData.Length); Assert.AreEqual(apiEntity1.Id, apiSync.DeletedData[0]); }
public async Task Get_ReturnOK_WithPingTrue() { // Arrange var dbContext = await GetSqliteDbContextAsync(); var loggerMock = new Mock <ILogger <SampleController> >(); var logger = loggerMock.Object; var fooMock = new Mock <IFoo>(); fooMock.Setup(foo => foo.Ping("localhost")).Returns(true); var foo = fooMock.Object; var controller = new SampleController(dbContext, logger, foo); // Act var response = await controller.Get(2); var responseModel = ((OkObjectResult)response).Value as SampleEntity; // Assert Assert.IsInstanceOfType(response, typeof(OkObjectResult)); Assert.IsTrue(responseModel.Id == 2); Assert.IsFalse(responseModel.BoolValue); Assert.IsTrue(responseModel.StringValue == "ping"); }
public async Task Get_ReturnOK_WithPingTrue_UsingFluentAssertions() { // Arrange var dbContext = await GetSqliteDbContextAsync(); var loggerMock = new Mock <ILogger <SampleController> >(); var logger = loggerMock.Object; var fooMock = new Mock <IFoo>(); fooMock.Setup(foo => foo.Ping("localhost")).Returns(true); var foo = fooMock.Object; var controller = new SampleController(dbContext, logger, foo); // Act var response = await controller.Get(2); // Assert var result = response.Should().BeOfType <OkObjectResult>().Subject; var sampleData = result.Value.Should().BeAssignableTo <SampleEntity>().Subject; sampleData.Id.Should().Be(2); sampleData.BoolValue.Should().BeFalse(); sampleData.StringValue.Should().Be("ping"); }
public void Get_Calls_FakeService() { var fakeServiceMock = new Mock <IFakeService>(); fakeServiceMock.Setup(x => x.AThirdAction()).Returns(4); var controller = new SampleController(fakeServiceMock.Object); var result = controller.Get(); Assert.NotNull(result); }
public void CanGetById() { var apiEntity = new ApiSample { Id = Guid.NewGuid() }; service.Write(apiEntity); var sampleController = new SampleController(service); var resultApiEntity = sampleController.Get(apiEntity.Id); Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, resultApiEntity)); }
public void TestGetHelloString() { var mockRepo = new Mock <ISampleService>(); mockRepo.Setup(x => x.GetString()).Returns((HttpStatusCode.OK, "Hello")); var controller = new SampleController(mockRepo.Object); IHttpActionResult actionResult = controller.Get(); var contentResult = actionResult as OkNegotiatedContentResult <object>; Assert.IsNotNull(contentResult); // Assert.AreEqual(HttpStatusCode.OK, contentResult.); Assert.IsNotNull(contentResult.Content); }
public async Task Get_NoCondition_ReturnList() { // Arrange var sampleList = new List <Sample>(); var apiResult = new OkObjectResult(sampleList); sampleService.Setup(x => x.GetAll()).ReturnsAsync(sampleList); // Act var result = await controller.Get(); // Assert result.Should().BeOfType <OkObjectResult>(); result.Should().BeEquivalentTo(apiResult); }
public async Task Get_ReturnOK_WithPingFalse() { // Arrange var dbContext = await GetSqliteDbContextAsync(); var loggerMock = new Mock <ILogger <SampleController> >(); var logger = loggerMock.Object; var fooMock = new Mock <IFoo>(); fooMock.Setup(foo => foo.Ping("localhost")).Returns(false); var foo = fooMock.Object; var controller = new SampleController(dbContext, logger, foo); // Act var response = await controller.Get(2); // Assert Assert.IsInstanceOfType(response, typeof(NotFoundResult)); }
public void Get_ReturnsSampleModels() { var result = _controller.Get(); Assert.IsAssignableFrom <IEnumerable <SampleModel> >(result); }