public void ResultShouldBeTrue() { using (PassContext context = new PassContext(InMemoryDbContextOptionsFactory.Create <PassContext>())) { var pass = new Pass { CardId = 124, CreatedOn = DateTime.Today.AddDays(-4) }; context.Passes.Add(pass); context.SaveChanges(); var mediatorMock = new Mock <IMediator>(); mediatorMock.Setup(m => m.Send(It.Is <ResolvePass>(r => r.CardId == 124 && r.LocationId == 432))).Returns(pass); var dateServiceMock = new Mock <IDateService>(); dateServiceMock.Setup(d => d.Now()).Returns(DateTime.Now); var controller = new ScanCardController(context, mediatorMock.Object, dateServiceMock.Object); var result = controller.Get(124, 432); Assert.IsType <OkObjectResult>(result); OkObjectResult okObjectResult = (OkObjectResult)result; Assert.Equal(true, okObjectResult.Value); } }
public void ThePassShouldNotBeActivatedAgain() { using (PassContext context = new PassContext(InMemoryDbContextOptionsFactory.Create <PassContext>())) { var pass = new Pass { CardId = 124, CreatedOn = DateTime.Today.AddDays(-4) }; context.Passes.Add(pass); context.SaveChanges(); var passActivation = new PassActivation { PassId = pass.Id, ScanId = 555 }; context.PassActivations.Add(passActivation); context.SaveChanges(); var mediatorMock = new Mock <IMediator>(); mediatorMock.Setup(m => m.Send(It.Is <CreateScan>(c => c.CardId == 124 && c.LocationId == 432))).Returns(555); mediatorMock.Setup(m => m.Send(It.Is <ResolvePass>(r => r.CardId == 124 && r.LocationId == 432))).Returns(pass); var dateServiceMock = new Mock <IDateService>(); dateServiceMock.Setup(d => d.Now()).Returns(DateTime.Now); var controller = new ScanCardController(context, mediatorMock.Object, dateServiceMock.Object); var result = controller.Get(124, 432); mediatorMock.Verify(m => m.Send(It.Is <ActivatePass>(p => p.PassId == pass.Id && p.ScanId == 555)), Times.Never); } }
public void CreateScanCommandShouldBeInvoked() { using (PassContext context = new PassContext(InMemoryDbContextOptionsFactory.Create <PassContext>())) { var dateServiceMock = new Mock <IDateService>(); dateServiceMock.Setup(d => d.Now()).Returns(DateTime.Now); var mediatorMock = new Mock <IMediator>(); var controller = new ScanCardController(context, mediatorMock.Object, dateServiceMock.Object); var result = controller.Get(124, 432); mediatorMock.Verify(m => m.Send(It.Is <CreateScan>(c => c.CardId == 124 && c.LocationId == 432))); } }
public void ResultShouldBeFalse() { using (PassContext context = new PassContext(InMemoryDbContextOptionsFactory.Create <PassContext>())) { var mediatorMock = new Mock <IMediator>(); mediatorMock.Setup(m => m.Send(It.Is <ResolvePass>(r => r.CardId == 124 && r.LocationId == 432))).Returns(default(Pass)); var dateServiceMock = new Mock <IDateService>(); dateServiceMock.Setup(d => d.Now()).Returns(DateTime.Now); var controller = new ScanCardController(context, mediatorMock.Object, dateServiceMock.Object); var result = controller.Get(124, 432); Assert.IsType <OkObjectResult>(result); OkObjectResult okObjectResult = (OkObjectResult)result; Assert.Equal(false, okObjectResult.Value); } }