public void Can_delete_item() { using (var context = new WebApiContext(ContextOptions)) { User usr = new User() { Name = "Test User" }; context.Users.Add(usr); Ticket t = new Ticket() { Name = "test write", User = usr }; context.Tickets.Add(t); context.SaveChanges(); int delete = t.Id; var controller = new TicketsController(context); var item = controller.Delete(delete); Ticket newticket = context.Tickets.FirstOrDefault(x => x.Id == delete); Assert.Null(newticket); Assert.IsType <ActionResult <Ticket> >(item.Result); } }
public async Task Test_TicketsController_GetTicketForUser() { // Setup. SeedDatabase(); TicketsController controllerUnderTest = new TicketsController(Database); // Check that the controller handles incorrect paramters. if (await controllerUnderTest.GetTicketForUser(null, null, null) != null) { Assert.Fail("Controller not handling incorrect parameters."); } if (await controllerUnderTest.GetTicketForUser("", "", "") != null) { Assert.Fail("Controller not handling incorrect parameters."); } if (await controllerUnderTest.GetTicketForUser("not_a_number", "could_be_valid", "could_be_valid") != null) { Assert.Fail("Controller not handling incorrect parameters."); } // Setup (Get a valid User to test with). User user = Database.Users.First(); if (user == null) { Assert.Fail("Seeded database not as expected for this test."); } string userId = user.Id; // Used as a cache to get the same User later on. JsonResult userTokenJson = await new UserController(Database).GetNewUserToken(user.UserName); // This Controller has been tested independently. if (userTokenJson == null) // Check that we didn't get an error from the controller and that we can continue. { Assert.Fail("Problem getting User Token for testing."); } user = Database.Users.FirstOrDefault(u => u.Id == userId); // Re-get the User from the database, as UserController should have changed it. if (user == null) { Assert.Fail("Logic problem with test, cannot continue."); } // Test that the controller returns the ticket that was requested. JsonResult ticketJson = await controllerUnderTest.GetTicketForUser("1", user.UserName, user.UserToken); if (ticketJson == null) { Assert.Fail("Recieved an error from the controller."); } if (ticketJson.ContentType != "Ticket") { Assert.Fail("Recieved incorrect data from controller."); } dynamic ticket = ticketJson.Data; if (!(ticket is ApiTicketViewModel)) { Assert.Fail("Recieved incorrect data type from controller."); } // TODO: Check for the handling of the User being internal/not internal. }
public void GetTicketsReturnsTickets() { var tickets = new List <Ticket>() { new Ticket() { TicketId = 1, ProductId = 1, SeverityId = 1, Description = "D1", Problem = "Pr1" }, new Ticket() { TicketId = 2, ProductId = 2, SeverityId = 2, Description = "D2", Problem = "Pr2" } }; var fakeStService = A.Fake <ISTAppService <ISTRepo> >(); A.CallTo(() => fakeStService.GetActiveTickets()).Returns(tickets); var ticketsController = new TicketsController(fakeStService); var result = ticketsController.GetTickets(); Assert.IsType <OkObjectResult>(result); var okObjectResult = ((OkObjectResult)result).Value; Assert.IsType <List <Ticket> >(okObjectResult); var listResult = (List <Ticket>)okObjectResult; Assert.True(listResult.Count == 2); }
public void Get_Should_get_all_tickets() { // Arrange var ticketservice = A.Fake <ITicketsService>(); A.CallTo(() => ticketservice.Get()).Returns(new List <TicketDTO> { ticket1In, ticket2In }); var ticketsController = new TicketsController(ticketservice); //Act var actionResult = ticketsController.GetAll(); //Assert Assert.NotNull(actionResult); OkObjectResult result = actionResult as OkObjectResult; Assert.NotNull(result); List <TicketDTO> tickets = result.Value as List <TicketDTO>; Assert.AreEqual(2, tickets.Count()); Assert.AreEqual(ticket1In, tickets[0]); Assert.AreEqual(ticket2In, tickets[1]); }
public void PutTicketStateToClosed_WithValidId_ReturnsNoContentAndUpdatesTicket() { // arrange int ticketId = 1; var mgr = new Mock <ITicketManager>(); mgr .Setup(x => x.GetTicket(ticketId)) .Returns(new Ticket() { TicketNumber = ticketId, State = TicketState.Open }); var controller = new TicketsController(mgr.Object); // act var result = controller.PutTicketStateToClosed(ticketId); // assert // var notFoundResult = Assert.IsType<NotFoundResult>(result); Assert.IsType <NoContentResult>(result); var ctrl2 = new TicketController(mgr.Object); Assert.Equal(TicketState.Closed, ((Ticket)((ViewResult)ctrl2.Details(ticketId)).Model).State); }
public TicketsControllerTests() { // Arrange mock of manager here _mockManager = new Mock <ITicketManager>(); // sut = system under test _sut = new TicketsController(Mock.Of <ILogger <TicketsController> >(), _mockManager.Object, new MockCachingService()); }
private void ticketUpdateBtn_Click(object sender, EventArgs e) { var ticket = new { id = ticketId, name = customerName.Text.Trim(), phone = phoneBox.Text.Trim(), source = ticketSource.Text.Trim(), destination = ticketDest.Text.Trim(), coach = coachBox.Text.Trim(), type = bustype, date = journeyDate.Value.ToShortDateString(), time = journeyTime.Text.Trim(), author = Author.Name, seat = reserve, booked }; bool res = TicketsController.updateTicket(ticket); if (res) { reloadTickets(); MessageBox.Show("Ticket updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void Can_put_item() { using (var context = new WebApiContext(ContextOptions)) { User usr = new User() { Name = "Test User" }; context.Users.Add(usr); Ticket t = new Ticket() { Name = "test write", User = usr }; context.Tickets.Add(t); context.SaveChanges(); Ticket newticket = context.Tickets.Find(t.Id); var controller = new TicketsController(context); t.Name = "new value"; var item = controller.Put(t); Assert.IsType <OkObjectResult>(item.Result); Assert.Equal(newticket, t); Assert.Equal("new value", newticket.Name); } }
public void Can_post_item() { using (var context = new WebApiContext(ContextOptions)) { User usr = new User() { Name = "Test User" }; context.Users.Add(usr); context.SaveChanges(); Ticket t = new Ticket() { Name = "test write", UserId = usr.Id }; var controller = new TicketsController(context); //t.Name = "new value"; var item = controller.Post(t).Result; Ticket newticket = context.Tickets.Find(t.Id); Assert.IsType <ActionResult <Ticket> >(item); Assert.Equal(t, newticket); } }
public UserRequestTicketsTests() { MapperSetUp(); var communicationServiceMock = new Mock <ICommunicationService>(); var ticketControllerLogMock = GetLoggerMock <TicketsController>(); var tagServiceLogMock = GetLoggerMock <TagService>(); var ticketLinkServiceLogMock = GetLoggerMock <TicketLinkService>(); var ticketServiceLogMock = GetLoggerMock <BLL.Services.TicketService>(); var tagService = new TagService(UnitOfWork, Mapper, tagServiceLogMock.Object); var ticketLinkService = new TicketLinkService(UnitOfWork, Mapper, ticketLinkServiceLogMock.Object); var ticketService = new BLL.Services.TicketService( UnitOfWork, Mapper, tagService, ticketLinkService, ticketServiceLogMock.Object); _sut = new TicketsController( Mapper, ticketService, communicationServiceMock.Object, ticketControllerLogMock.Object); }
public void Delete_Ticket() { var controller = new TicketsController(new TicketRepositoryMock(), new ClientRepositoryMock(), new InventoryServiceMock(), new HRServiceMock()); var result = controller.Delete(TicketRepositoryMock.TestTicket.Id); var resultOk = result.Should().BeOfType <NoContentResult>().Subject; }
public void DetailsTest() { // Arrange List <Ticket> lista = GetFakeTickets(); var dbTicketMock = new Mock <DbSet <Ticket> >(); dbTicketMock.As <IQueryable <Ticket> >().Setup(m => m.Provider).Returns(lista.AsQueryable().Provider); dbTicketMock.As <IQueryable <Ticket> >().Setup(m => m.Expression).Returns(lista.AsQueryable().Expression); dbTicketMock.As <IQueryable <Ticket> >().Setup(m => m.ElementType).Returns(lista.AsQueryable().ElementType); dbTicketMock.As <IQueryable <Ticket> >().Setup(m => m.GetEnumerator()).Returns(lista.AsQueryable().GetEnumerator()); dbTicketMock.Setup(m => m.Find(It.IsAny <object[]>())) .Returns <object[]>(ids => lista.FirstOrDefault(x => x.Id == (int)ids[0])); var dbContextMock = new Mock <ApplicationDbContext>(); dbContextMock.SetupGet <DbSet <Ticket> >(x => x.Tickets) .Returns(dbTicketMock.Object); TicketsController controller = new TicketsController(dbContextMock.Object); // Act ViewResult result = controller.Details(1) as ViewResult; // Assert Assert.IsNotNull(result); }
public string CreateTicket(string GoogleId, string FunctionType) { AspNetUser branch = db.AspNetUsers.Where(m => m.BranchGoogleId == GoogleId).SingleOrDefault(); FunctionType function = db.FunctionTypes.Where(m => m.FunctionName == FunctionType).SingleOrDefault(); if (branch == null) { return("Branch Not Found"); } DateTime Now = DateTime.Now; int ticketNumber = new TicketsController().getNextTicketNumber(branch.Id); Ticket ticket = new Ticket() { TicketNumber = ticketNumber, DateTimeIssued = Now, FunctionTypeId = function.Id, BranchId = branch.Id }; db.Tickets.Add(ticket); db.SaveChanges(); var data = new[] { new { value = ticket.Id, data = ticket.TicketNumber }, }; return(JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented)); }
public UserManagesWithTicketAssignees() { MapperSetUp(); _communicationServiceMock = new Mock <ICommunicationService>(); var ticketsControllerLogMock = GetLoggerMock <TicketsController>(); var tagServiceLogMock = GetLoggerMock <TagService>(); var ticketLinkServiceLogMock = GetLoggerMock <TicketLinkService>(); var ticketServiceLogMock = GetLoggerMock <BLL.Services.TicketService>(); var tagService = new TagService(UnitOfWork, Mapper, tagServiceLogMock.Object); var ticketLinkService = new TicketLinkService(UnitOfWork, Mapper, ticketLinkServiceLogMock.Object); var ticketService = new BLL.Services.TicketService( UnitOfWork, Mapper, tagService, ticketLinkService, ticketServiceLogMock.Object); _sut = new TicketsController( Mapper, ticketService, _communicationServiceMock.Object, ticketsControllerLogMock.Object); SetupRequestHeader(_sut); }
public TicketsControllerTests() { _config = new ParkingLotConfig { MaxParkingSpaces = 5 }; _mockTicketService = new Mock <ITicketService>(); _controller = new TicketsController(_config, _mockTicketService.Object); }
public FullAPITests() { var kernel = new StandardKernel(new AirPortServiceModule()); var mapper = MyMapperConfiguration.GetConfiguration().CreateMapper(); _flightController = new FlightsController(mapper, kernel.Get <AirportService>()); _ticketController = new TicketsController(mapper, kernel.Get <AirportService>()); }
public async Task GetTicketAsync__An_unexpected_internal_error_occurred__Should_throw_Exception() { _ticketDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new Exception()); var controller = new TicketsController(_ticketDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.GetTicketAsync("1"); await result.Should().ThrowExactlyAsync <Exception>(); }
private void ticketCancelBtn_Click(object sender, EventArgs e) { bool res = TicketsController.cancelTicket(ticketId); if (res) { reloadTickets(); MessageBox.Show("Ticket Cancelled", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public async Task GetCustomerTicket__Argument_customerId_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string customerId) { var controller = new TicketsController(_ticketDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.GetCustomerTicketsAsync(customerId); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError()); }
public TicketsControllerTest() { this.mockMementoService = new Mock <IMementoService>(MockBehavior.Strict); this.mockTicketService = new Mock <ITicketService>(MockBehavior.Strict); this.controller = InitializeController(new TicketsController( ValidationServiceMock.Object, mockMementoService.Object, mockTicketService.Object)); }
public void Cant_get_item_if_not_exist() { using (var context = new WebApiContext(ContextOptions)) { var controller = new TicketsController(context); var item = controller.Get(9999999).Result.Value; Assert.Null(item); } }
public TicketControllerTest() { this.mirRep = new Mocks.MirrorRepository(); this.controller = new TicketsController(new Mocks.TicketRepository(), mirRep, new DummySocket()); this.controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() }; }
public void Get_All_Ticket() { var controller = new TicketsController(new TicketRepositoryMock(), new ClientRepositoryMock(), new InventoryServiceMock(), new HRServiceMock()); var result = controller.Get(null); var okResult = result.Should().BeOfType <OkObjectResult>().Subject; var tickets = okResult.Value.Should().BeAssignableTo <IEnumerable <TicketWithClientAndAgentDto> >().Subject; tickets.Count().Should().Be(1); }
public async Task GetTicketAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id) { _ticketDbServiceMock.Setup(x => x.GetAsync(id)).ThrowsAsync(new ArgumentException()); var controller = new TicketsController(_ticketDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.GetTicketAsync(id); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError()); }
public async Task GetCustomerTicket__Customer_not_found__Should_return_404NotFound_response() { _ticketDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <Ticket, bool> > >())).ReturnsAsync(Enumerable.Empty <Ticket>()); var controller = new TicketsController(_ticketDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.GetCustomerTicketAsync("1", "1"); (result as ObjectResult).StatusCode.Should().Be(404); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError()); }
public async Task GetTicketAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException() { // Example of these errors: database does not exist, table does not exist etc. _ticketDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new InternalDbServiceException()); var controller = new TicketsController(_ticketDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.GetTicketAsync("1"); await result.Should().ThrowExactlyAsync <InternalDbServiceException>(); }
public async Task GetTicketAsync__Element_not_found__Should_return_404NotFound_response() { _ticketDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ThrowsAsync(new InvalidOperationException()); var controller = new TicketsController(_ticketDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.GetTicketAsync("1"); (result as ObjectResult).StatusCode.Should().Be(404); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError()); }
public TicketControllerUnitTests() { _mockRepo = new Mock <IUnitOfWork <Main_MadPayDbContext> >(); _mockMapper = new Mock <IMapper>(); _mockLogger = new Mock <ILogger <TicketsController> >(); _mockUploadService = new Mock <IUploadService>(); _mockEenv = new Mock <IWebHostEnvironment>(); _controller = new TicketsController(_mockRepo.Object, _mockMapper.Object, _mockLogger.Object, _mockUploadService.Object, _mockEenv.Object); }
public void Initialize() { db = Substitute.For <IDatabase>(); connectionManager = Substitute.For <IConnectionManager>(); hubContext = Substitute.For <IHubContext>(); connectionManager.GetHubContext <TicketHub>().Returns(hubContext); sut = new TicketsController(db, connectionManager); }
public void Get_Ticket() { var controller = new TicketsController(new TicketRepositoryMock(), new ClientRepositoryMock(), new InventoryServiceMock(), new HRServiceMock()); var result = controller.Get(TicketRepositoryMock.TestTicket.Id); var okResult = result.Should().BeOfType <OkObjectResult>().Subject; var ticket = okResult.Value.Should().BeAssignableTo <TicketWithClientAndAgentDto>().Subject; ticket.Title.Should().Be(TicketRepositoryMock.TestTicket.Title); }