Ejemplo n.º 1
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);
                }
            }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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);
                }
            }
            public void PassesAddedEvents_is_published_for_each_pass()
            {
                using (PassContext context =
                           GetContext())
                {
                    var mediator    = new Mock <IMediator>();
                    var dateService = new Mock <IDateService>();
                    var currentDate = DateTime.UtcNow;
                    dateService.Setup(x => x.Now()).Returns(currentDate);
                    var sut = new AddSkiPassOnPurchaseCompleted(context, mediator.Object, dateService.Object);

                    sut.Handle(new Events.PurchaseCompleted
                    {
                        Passes = new List <PassPurchased>
                        {
                            passPurchased
                        }
                    });
                    var dbPass = context.Passes.Single();
                    mediator.Verify(x => x.Publish(It.Is <PassAdded>(y => y.CardId == passPurchased.CardId &&
                                                                     y.CreatedOn == currentDate &&
                                                                     y.PassId == dbPass.Id &&
                                                                     y.PassTypeId == passPurchased.PassTypeId)));
                }
            }
Ejemplo n.º 5
0
 public PassValidityChecker(IDateService dateService,
                            PassContext passContext,
                            PassTypeContext passTypeContext)
 {
     _passTypeContext = passTypeContext;
     _passContext     = passContext;
     _dateService     = dateService;
 }
Ejemplo n.º 6
0
            public void The_pass_activated_event_is_raised()
            {
                using (PassContext context = GetContext())
                {
                    Mock <IMediator> mediatorMock = new Mock <IMediator>();

                    var sut          = new ActivatePassHandler(context, mediatorMock.Object);
                    var activationId = sut.Handle(activatePass);

                    mediatorMock.Verify(m => m.Publish(It.Is <PassActivated>(c => c.PassActivationId == activationId)));
                }
            }
Ejemplo n.º 7
0
            public void The_card_scanned_event_is_raised()
            {
                using (PassContext context = GetContext())
                {
                    var dateService = new Mock <IDateService>();
                    var currentDate = DateTime.UtcNow;
                    dateService.Setup(x => x.Now()).Returns(currentDate);
                    Mock <IMediator> mediatorMock = new Mock <IMediator>();

                    var sut    = new CreateScanHandler(context, dateService.Object, mediatorMock.Object);
                    var scanId = sut.Handle(createScan);

                    mediatorMock.Verify(m => m.Publish(It.Is <CardScanned>(c => c.ScanId == scanId)));
                }
            }
Ejemplo n.º 8
0
            public void A_new_pass_activation_is_saved_to_the_database()
            {
                using (PassContext context = GetContext())
                {
                    var currentDate = DateTime.UtcNow;
                    Mock <IMediator> mediatorMock = new Mock <IMediator>();

                    var sut = new ActivatePassHandler(context, mediatorMock.Object);
                    sut.Handle(activatePass);

                    Assert.Equal(1, context.PassActivations.Count());
                    var passActivateThatWasAdded = context.PassActivations.Single();
                    Assert.Equal(activatePass.PassId, passActivateThatWasAdded.PassId);
                    Assert.Equal(activatePass.ScanId, passActivateThatWasAdded.ScanId);
                }
            }
Ejemplo n.º 9
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 void Empty_passes_collection_saves_nothing_to_the_database()
            {
                using (PassContext context = GetContext())
                {
                    var mediator    = new Mock <IMediator>();
                    var dateService = new Mock <IDateService>();
                    var currentDate = DateTime.UtcNow;
                    dateService.Setup(x => x.Now()).Returns(currentDate);
                    var sut = new AddSkiPassOnPurchaseCompleted(context, mediator.Object, dateService.Object);
                    sut.Handle(new Events.PurchaseCompleted {
                        Passes = new List <PassPurchased>()
                    });

                    Assert.Equal(0, context.Passes.Count());
                }
            }
Ejemplo n.º 11
0
        public async Task <IActionResult> Signup([FromBody] Login val)
        {
            UserDataContext userDatadb = new UserDataContext();
            UserNContext    userNamedb = new UserNContext();
            PassContext     passworddb = new PassContext();

            //At this stage we have no userData besides the ID
            //Creating this object automatically generates an ID
            UserDataDB userData = new UserDataDB();

            //Create new username and password database entries with the same key
            UserNDB userName = new UserNDB(userData.UserId);

            userName.Email    = val.email;
            userName.UserName = val.username;
            PassDB password = new PassDB(userData.UserId);

            password.Password = val.password;

            userDatadb.Add(userData);
            userNamedb.Add(userName);
            passworddb.Add(password);

            //update the databases
            try
            {
                userDatadb.SaveChanges();
                userNamedb.SaveChanges();
                passworddb.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(Ok(200));

            //string newUser = JsonSerializer.Serialize(val);
            //bool complete = await be.incomming(1, 3, newUser);
            //bool complete = true;
            //if (complete)
            //{
            //    return Ok(200);
            //}
            //return BadRequest(400);
        }
            public void Empty_passes_collection_publishes_no_messages()
            {
                using (PassContext context = GetContext())
                {
                    var mediator    = new Mock <IMediator>();
                    var dateService = new Mock <IDateService>();
                    var currentDate = DateTime.UtcNow;
                    dateService.Setup(x => x.Now()).Returns(currentDate);
                    var sut = new AddSkiPassOnPurchaseCompleted(context, mediator.Object, dateService.Object);

                    sut.Handle(new Events.PurchaseCompleted {
                        Passes = new List <PassPurchased>()
                    });

                    mediator.Verify(x => x.Publish(It.IsAny <PassAdded>()), Times.Never);
                }
            }
Ejemplo n.º 13
0
            public void A_new_scan_is_saved_to_the_database()
            {
                using (PassContext context = GetContext())
                {
                    var dateService = new Mock <IDateService>();
                    var currentDate = DateTime.UtcNow;
                    dateService.Setup(x => x.Now()).Returns(currentDate);
                    Mock <IMediator> mediatorMock = new Mock <IMediator>();

                    var sut = new CreateScanHandler(context, dateService.Object, mediatorMock.Object);
                    sut.Handle(createScan);

                    Assert.Equal(1, context.Scans.Count());
                    var scanThatWasAdded = context.Scans.Single();
                    Assert.Equal(createScan.CardId, scanThatWasAdded.CardId);
                    Assert.Equal(createScan.LocationId, scanThatWasAdded.LocationId);
                    Assert.Equal(currentDate, scanThatWasAdded.DateTime);
                }
            }
Ejemplo n.º 14
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);
                }
            }
            public void Pass_is_saved_to_the_database_for_each_pass()
            {
                using (PassContext context = GetContext())
                {
                    var mediator    = new Mock <IMediator>();
                    var dateService = new Mock <IDateService>();
                    var currentDate = DateTime.UtcNow;
                    dateService.Setup(x => x.Now()).Returns(currentDate);
                    var sut = new AddSkiPassOnPurchaseCompleted(context, mediator.Object, dateService.Object);
                    sut.Handle(new Events.PurchaseCompleted
                    {
                        Passes = new List <PassPurchased>
                        {
                            passPurchased
                        }
                    });

                    Assert.Equal(1, context.Passes.Count());
                    Assert.Equal(passPurchased.CardId, context.Passes.Single().CardId);
                    Assert.Equal(passPurchased.PassTypeId, context.Passes.Single().PassTypeId);
                    Assert.Equal(currentDate, context.Passes.Single().CreatedOn);
                }
            }
Ejemplo n.º 16
0
 public ActivatePassHandler(PassContext passContext, IMediator mediator)
 {
     _passContext = passContext;
     _mediator    = mediator;
 }
Ejemplo n.º 17
0
 public ResolvePassHandler(PassContext context, IPassValidityChecker validator)
 {
     _context   = context;
     _validator = validator;
 }
Ejemplo n.º 18
0
 public ScanCardController(PassContext passContext, IMediator mediator, IDateService dateService)
 {
     _passContext = passContext;
     _mediator    = mediator;
     _dateService = dateService;
 }
Ejemplo n.º 19
0
 public AddSkiPassOnPurchaseCompleted(PassContext passContext, IMediator bus)
 {
     _passContext = passContext;
     _bus         = bus;
 }
Ejemplo n.º 20
0
 public PassController(PassContext passContext, PassTypeContext passTypeContext)
 {
     _passTypeContext = passTypeContext;
     _passContext     = passContext;
 }
Ejemplo n.º 21
0
 public CreateScanHandler(PassContext passContext, IDateService dateService, IMediator mediator)
 {
     _dateService = dateService;
     _passContext = passContext;
     _mediator    = mediator;
 }
Ejemplo n.º 22
0
 public AddSkiPassOnPurchaseCompleted(PassContext passContext, IMediator bus, IDateService dateService)
 {
     _dateService = dateService;
     _passContext = passContext;
     _bus         = bus;
 }
Ejemplo n.º 23
0
 public PassValidityCheckerTests()
 {
     _mockDateService = new Mock <IDateService>();
     _passContext     = new PassContext(InMemoryDbContextOptionsFactory.Create <PassContext>());
     _passTypeContext = new PassTypeContext(InMemoryDbContextOptionsFactory.Create <PassTypeContext>());
 }