public async Task GetItemFound() { var item = new TestEntity() { Id = 123, Name = "Uom123" }; var mockRepository = new Mock <IReadRepository <TestEntity> >(MockBehavior.Strict); mockRepository.Setup(r => r.GetAsync(123)).ReturnsAsync(item); var supportedMedia = new LrpSupportedMedia(); var context = new ControllerContext { HttpContext = new DefaultHttpContext() }; context.HttpContext.Request.Headers["Accept"] = "application/vnd.lrp.v1+json"; var pageLinksBuilder = new Mock <IPageLinksBuilder>(MockBehavior.Strict).Object; var controller = new ReadController <TestEntity>(mockRepository.Object, pageLinksBuilder) { ControllerContext = context }; var actionResult = await controller.GetItemAsync(123) as OkObjectResult; Assert.NotNull(actionResult); var dataResult = actionResult.Value as TestEntity; Assert.NotNull(dataResult); Assert.AreEqual(123, dataResult.Id); Assert.AreEqual("Uom123", dataResult.Name); }
public override async Task ExecuteAsync(List <string> arguments) { if (arguments.Count != EXPECTED_ARGUMENTS) { Console.WriteLine("Expected " + EXPECTED_ARGUMENTS + " arguments but found " + arguments.Count + "."); return; } string partitionId = arguments.ElementAt(0); string objectId = arguments.ElementAt(1); string serverId = arguments.ElementAt(2); try { Console.WriteLine($"Read... {partitionId} {objectId} {serverId}"); GStoreObject gstoreObject = await ReadController.Execute(ConnectionManager, partitionId, serverId, objectId); Console.WriteLine($"PartitionId: {gstoreObject.Identifier.PartitionId} | ObjectId: {gstoreObject.Identifier.ObjectId} | Value: {gstoreObject.Value}"); } catch (ServerBindException e) { Console.WriteLine($"ERROR: {e.Message}"); } catch (RpcException ex) when(ex.StatusCode == StatusCode.Internal) { Console.WriteLine($"Could not establish connection with server."); } }
public void GetPageLinksBuilderThrows() { var page = new Page <TestEntity>("", 40, 0, 10, new List <TestEntity>()); var mockRepository = new Mock <IReadRepository <TestEntity> >(MockBehavior.Strict); mockRepository.Setup(r => r.GetAsync("", 0, 20)).ReturnsAsync(page); var supportedMedia = new LrpSupportedMedia(); var context = new ControllerContext { HttpContext = new DefaultHttpContext() }; context.HttpContext.Request.Headers["Accept"] = "application/vnd.lrp.v1+json"; var pageLinksBuilder = new Mock <IPageLinksBuilder>(); pageLinksBuilder.Setup(p => p.Build(page, context.HttpContext.Request)).Throws(new Exception()); var controller = new ReadController <TestEntity>(mockRepository.Object, pageLinksBuilder.Object) { ControllerContext = context }; Assert.ThrowsAsync <Exception>(async() => await controller.GetPageAsync("", 0, 20)); }
private async Task CreateController() { using (await BusyOverlay.Create()) { _book = _bookRepository.Get(ViewModel.BookId); if (_book == null) { return; } _readController = new ReadController(PageCanvas, ViewModel.BookId, _bookRepository, ViewModel.TokenOffset); await _readController.ShowNextPage(); PageCanvas.Manipulator.UpdatePanelsVisibility(); PageCanvas.Manipulator.IsFirstPage = _readController.IsFirst; PageCanvas.Manipulator.IsLastPage = _readController.IsLast; AppBar.TotalPages = _readController.TotalPages; AppBar.PageNumber = _readController.CurrentPage; AppBar.MenuItems[2].IsEnabled = ViewModel.CanPinToDesktop; if (_book.Trial) { AppBar.IconButtons = CreateAppBarIconsForTrial(); } else { AppBar.IconButtons[2].IsEnabled = true; UpdateIsFavouriteAppBarButton(_book.IsFavourite); } } }
public async Task GetPaymentsByMerchantId_When_MerchantId_Is_Null_Then_Return_BadRequest() { var controller = new ReadController(_logger, _mockReadService.Object); var expected = new BadRequestResult(); var actual = await controller.GetPaymentsByMerchantId(null); actual.Should().BeEquivalentTo(expected); }
public async Task Test_ReadControllerGetByIdFailed() { //Arrange ReadController readController = new ReadController(this._UoW); //Act var results = await readController.Get(-1) as StatusCodeResult; //Assert Assert.IsNotNull(results); Assert.AreEqual(results.StatusCode, (int)System.Net.HttpStatusCode.NotFound); }
public async Task Test_ReadControllerGetAllSuccess() { //Arrange ReadController readController = new ReadController(this._UoW); //Act var results = await readController.GetAll() as ObjectResult; //Assert Assert.IsNotNull(results); Assert.AreEqual(results.StatusCode, (int)System.Net.HttpStatusCode.OK); Assert.IsTrue(results.Value is IEnumerable <Employee>); }
public async Task GetPaymentsByMerchantId_When_Exception_Is_Thrown_Then_Return_InternalServerError() { var merchantId = 123123; var controller = new ReadController(_logger, _mockReadService.Object); _mockReadService.Setup(x => x.GetByMerchantId(It.IsAny <int>())) .ThrowsAsync(new Exception()); var expected = new StatusCodeResult(500); var actual = await controller.GetPaymentsByMerchantId(merchantId); actual.Should().BeEquivalentTo(expected); _mockReadService.Verify(); }
/// <summary> /// The application entry point. /// </summary> /// <param name="args"> /// The command line arguments. /// </param> static void Main(string[] args) { // INITIALISE an IReadController, IWriteController, IFilterController, IReportController as their respective // concrete implementations, ReadController, WriteController, FilterController and ReportController IReadController readController = new ReadController(); IWriteController writeController = new WriteController(); IFilterController filterController = new FilterController(); IReportController reportController = new ReportController(); // INITIALISE an IExportController as ExportController, passing in the readController and WriteController IExportController conversationExporter = new ExportController(readController, writeController, filterController, reportController); ConversationExporterConfiguration configuration = new CommandLineArgumentParser().ParseCommandLineArguments(args, filterController); conversationExporter.ExportConversation(configuration.inputFilePath, configuration.outputFilePath); }
public async Task GetPaymentsByMerchantId_When_MerchantId_Has_Zero_Then_Return_Ok_With_Empty_List() { var merchantId = 123; var payments = new List <Payment>(); _mockReadService .Setup(x => x.GetByMerchantId(merchantId)) .ReturnsAsync(payments); var controller = new ReadController(_logger, _mockReadService.Object); var expected = new OkObjectResult(payments); var actual = await controller.GetPaymentsByMerchantId(merchantId); actual.Should().BeEquivalentTo(expected); _mockReadService.Verify(); }
public async Task GetPageTakeLessThan1() { var mockRepository = new Mock <IReadRepository <TestEntity> >(MockBehavior.Strict).Object; var supportedMedia = new LrpSupportedMedia(); var pageLinksBuilder = new Mock <IPageLinksBuilder>(MockBehavior.Strict).Object; var controller = new ReadController <TestEntity>(mockRepository, pageLinksBuilder); var actionResult = await controller.GetPageAsync("", 0, 0) as BadRequestObjectResult; Assert.NotNull(actionResult); var message = actionResult.Value as string; Assert.NotNull(message); Assert.AreEqual(ReadController <TestEntity> .BadTakeMessage, actionResult.Value); }
public async Task GetPageSucceeds() { var page = new Page <TestEntity>("", 40, 0, 10, new List <TestEntity> { new TestEntity { Id = 1001, Name = "TheEntity" } }); var mockRepository = new Mock <IReadRepository <TestEntity> >(MockBehavior.Strict); mockRepository.Setup(r => r.GetAsync("", 0, 20)).ReturnsAsync(page); var supportedMedia = new LrpSupportedMedia(); var context = new ControllerContext { HttpContext = new DefaultHttpContext() }; context.HttpContext.Request.Headers["Accept"] = "application/vnd.lrp.v1+json"; var pageLinksBuilder = new Mock <IPageLinksBuilder>(); pageLinksBuilder.Setup(p => p.Build(page, context.HttpContext.Request)).Returns("daLinks"); var controller = new ReadController <TestEntity>(mockRepository.Object, pageLinksBuilder.Object) { ControllerContext = context }; var actionResult = await controller.GetPageAsync("", 0, 20) as OkObjectResult; Assert.NotNull(actionResult); var items = actionResult.Value as ImmutableList <TestEntity>; Assert.NotNull(items); Assert.AreEqual(1, items.Count); Assert.AreEqual(1001, items[0].Id); Assert.AreEqual("TheEntity", items[0].Name); }
public async Task GetPaymentsByMerchantId_When_MerchantId_Has_Payments_Then_Return_Ok_With_Payment_List() { var merchantId = 123; var payments = new List <Payment> { new Payment() { PaymentId = 321, MerchantId = merchantId, Amount = 432.23m, Currency = "USD" } }; _mockReadService .Setup(x => x.GetByMerchantId(merchantId)) .ReturnsAsync(payments); var controller = new ReadController(_logger, _mockReadService.Object); var expected = new OkObjectResult(payments); var actual = await controller.GetPaymentsByMerchantId(merchantId); actual.Should().BeEquivalentTo(expected); _mockReadService.Verify(); }
public async Task GetItemNotFound() { var mockRepository = new Mock <IReadRepository <TestEntity> >(MockBehavior.Strict); mockRepository.Setup(r => r.GetAsync(123)).ReturnsAsync(null as TestEntity); var supportedMedia = new LrpSupportedMedia(); var context = new ControllerContext { HttpContext = new DefaultHttpContext() }; context.HttpContext.Request.Headers["Accept"] = "application/vnd.lrp.v1+json"; var pageLinksBuilder = new Mock <IPageLinksBuilder>(MockBehavior.Strict).Object; var controller = new ReadController <TestEntity>(mockRepository.Object, pageLinksBuilder) { ControllerContext = context }; var result = await controller.GetItemAsync(123) as NotFoundResult; Assert.NotNull(result); }
public void GetItemRepoThrows() { var mockRepository = new Mock <IReadRepository <TestEntity> >(MockBehavior.Strict); mockRepository.Setup(r => r.GetAsync(123)).ThrowsAsync(new IOException()); var supportedMedia = new LrpSupportedMedia(); var context = new ControllerContext { HttpContext = new DefaultHttpContext() }; context.HttpContext.Request.Headers["Accept"] = "application/vnd.lrp.v1+json"; var pageLinksBuilder = new Mock <IPageLinksBuilder>(MockBehavior.Strict).Object; var controller = new ReadController <TestEntity>(mockRepository.Object, pageLinksBuilder) { ControllerContext = context }; Assert.ThrowsAsync <IOException>(async() => await controller.GetItemAsync(123)); }
public ProductServiceReadTest() { this.controller = new ReadController(); }
public EmployeeService() { readController = new ReadController(); }