public async void GetAll_WhenFound() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var skuServiceMoq = new Mock<ISkuService>(); skuServiceMoq.Setup(x => x.GetAll()) .ReturnsAsync(() => new Result<IEnumerable<Sku>>(ResultCode.Success, TestSkus())); var dataStructureConverterMoq = new Mock<IDataStructureConverter>(); dataStructureConverterMoq.Setup(x => x.Convert(It.IsAny<string>(), It.IsAny<object>())) .Returns(new Dictionary<string, object> { { "skus", SkuHelper.GetMany() } }); var sut = new SkusController(skuServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAll(); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary<string, object>; // assert Assert.Equal(200, okResult.StatusCode); }
public async void GetAll_WhenNotFound() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var skuServiceMoq = new Mock<ISkuService>(); skuServiceMoq.Setup(x => x.GetAll()) .ReturnsAsync(() => new Result<IEnumerable<Sku>>(ResultCode.NotFound)); var dataStructureConverterMoq = new Mock<IDataStructureConverter>(); dataStructureConverterMoq.Setup(x => x.Convert(It.IsAny<string>(), It.IsAny<object>())) .Returns(new Dictionary<string, object> { { "skus", SkuHelper.GetMany() } }); var sut = new SkusController(skuServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAll(); var notFoundResult = result as NotFoundResult; // assert Assert.NotNull(notFoundResult); }
private IEnumerable<Sku> TestSkus() { return SkuHelper.GetMany(); }