Beispiel #1
0
        public void Should_check_context_using_provided_card_id()
        {
            var context         = new PassContext(InMemoryDbContextOptionsFactory.Create <PassContext>());
            var cardId          = 1337;
            var verifyingPassId = 7331;

            context.Passes.Add(new Pass {
                CardId = cardId, Id = 7330
            });
            context.Passes.Add(new Pass {
                CardId = cardId, Id = verifyingPassId
            });
            context.Passes.Add(new Pass {
                CardId = cardId, Id = 7332
            });
            context.SaveChanges();

            var validator = new Mock <IPassValidityChecker>();

            validator.Setup(c => c.IsValid(It.IsAny <int>()))
            .Returns <int>(i => context.Passes.Any(p => p.CardId == i));

            var handler = new ResolvePassHandler(context, validator.Object);

            handler.Handle(new Queries.ResolvePass {
                CardId = cardId
            });

            validator.Verify(v => v.IsValid(It.Is <int>(i => i == verifyingPassId)), Times.Once);
            validator.Verify(v => v.IsValid(It.IsAny <int>()), Times.Exactly(3));
        }
            public GivenAHackerTriesToEditSomeoneElsesSkiCard()
            {
                _skiCardContext =
                    new SkiCardContext(InMemoryDbContextOptionsFactory.Create <SkiCardContext>());
                _skiCard = new SkiCard
                {
                    ApplicationUserId = Guid.NewGuid().ToString(),
                    Id = 5,
                    CardHolderFirstName   = "James",
                    CardHolderLastName    = "Chambers",
                    CardHolderBirthDate   = DateTime.Now.AddYears(-150),
                    CardHolderPhoneNumber = "555-555-5555",
                    CreatedOn             = DateTime.UtcNow
                };

                _skiCardContext.SkiCards.Add(_skiCard);
                _skiCardContext.SaveChanges();


                _badGuyPrincipal   = new ClaimsPrincipal();
                _controllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext
                    {
                        User = _badGuyPrincipal
                    }
                };

                _mockAuthorizationService = new Mock <IAuthorizationService>();
            }
Beispiel #3
0
            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);
                }
            }
Beispiel #4
0
            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);
                }
            }
Beispiel #5
0
 public TopicExist()
 {
     _dbContext = new AppDbContext(InMemoryDbContextOptionsFactory.Create <AppDbContext>());
     _dbContext.Add(new Subject()
     {
         Name = _subjectName, Password = _passwordHash
     });
     _dbContext.SaveChanges();
     _controller = new HomeController(_dbContext, new MyStringLocalizer(), null, null);
 }
Beispiel #6
0
            public NoRecords()
            {
                _dbContext = new AppDbContext(InMemoryDbContextOptionsFactory.Create <AppDbContext>());
                _dbContext.Add(new Subject {
                    Id = _subjectId, Name = _subjectName
                });
                _dbContext.SaveChanges();

                _controller = new RecordController(_dbContext, new MyStringLocalizer(), null, null);
            }
Beispiel #7
0
            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 async Task EditActionShouldReturnNotFound()
            {
                using (SkiCardContext context =
                           new SkiCardContext(InMemoryDbContextOptionsFactory.Create <SkiCardContext>()))
                {
                    var logger     = new Mock <ILogger <SkiCardController> >();
                    var uploader   = new Mock <IBlobFileUploadService>();
                    var controller = new SkiCardController(context, null, null, uploader.Object, logger.Object);
                    var result     = await controller.Edit(new EditSkiCardViewModel
                    {
                        Id = 2,
                        CardHolderFirstName   = "Dave",
                        CardHolderLastName    = "Paquette",
                        CardHolderBirthDate   = DateTime.Now.AddYears(-99),
                        CardHolderPhoneNumber = "555-123-1234"
                    });

                    Assert.IsType <NotFoundResult>(result);
                }
            }
Beispiel #9
0
            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);
                }
            }
Beispiel #10
0
 public PassValidityCheckerTests()
 {
     _mockDateService = new Mock <IDateService>();
     _passContext     = new PassContext(InMemoryDbContextOptionsFactory.Create <PassContext>());
     _passTypeContext = new PassTypeContext(InMemoryDbContextOptionsFactory.Create <PassTypeContext>());
 }
Beispiel #11
0
 private PassContext GetContext()
 {
     return(new PassContext(InMemoryDbContextOptionsFactory.Create <PassContext>()));
 }
Beispiel #12
0
 public TopicNotExist()
 {
     _dbContext  = new AppDbContext(InMemoryDbContextOptionsFactory.Create <AppDbContext>());
     _controller = new HomeController(_dbContext, new MyStringLocalizer(), null, null);
 }