Ejemplo n.º 1
0
        public async void TestInvalidSerial()
        {
            options = new DbContextOptionsBuilder <RaffleDbContext>()
                      .UseInMemoryDatabase(databaseName: "TestInvalidEntryDatabase").Options;
            RaffleDbContext  context    = new RaffleDbContext(options);
            RaffleController controller = new RaffleController(context);

            context.Serialnumbers.Add(new Serialnumber {
                Number = 1754
            });

            Raffle rafValid = new Raffle
            {
                Firstname = "Jane",
                Lastname  = "Doe",
                Age       = 20,
                Number    = 6821,
                Email     = "*****@*****.**"
            };

            context.SaveChanges();
            var result = await controller.Create(rafValid);

            Assert.False(context.Raffle.Any(), "Entry was added, with invalid Serial");
        }
Ejemplo n.º 2
0
        public async void NoDuplicateSoldProduct()
        {
            Guid        serial  = Guid.NewGuid();
            SoldProduct product = new SoldProduct {
                SerialNumber = serial
            };

            RaffleDbContext context = getDb("NoDupe");

            context.SoldProducts.Add(product);
            await context.SaveChangesAsync();

            RaffleEntry entry = getEntry();

            entry.SoldProduct.SerialNumber = serial;

            RaffleApiController controller = new RaffleApiController(
                context,
                new EntryValidator());

            IStatusCodeActionResult result = await controller.PostRaffleEntry(entry);

            StatusCodeResult statusResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.OK, statusResult.StatusCode);

            Assert.Equal(1, await context.SoldProducts.CountAsync());
        }
Ejemplo n.º 3
0
        public async void TestValidAge()
        {
            options = new DbContextOptionsBuilder <RaffleDbContext>()
                      .UseInMemoryDatabase(databaseName: "TestCreateValidEntryDatabase").Options;
            RaffleDbContext  context    = new RaffleDbContext(options);
            RaffleController controller = new RaffleController(context);

            context.Serialnumbers.Add(new Serialnumber {
                Number = 6821
            });

            Raffle rafValid = new Raffle
            {
                Firstname = "Jane",
                Lastname  = "Doe",
                Age       = 20,
                Number    = 6821,
                Email     = "*****@*****.**"
            };

            context.SaveChanges();
            var result = await controller.Create(rafValid);

            ViewResult viewResult = Assert.IsType <ViewResult>(result);

            Assert.True(context.Raffle.Any(), "Entry wasn't added, with valid age and serial");
        }
Ejemplo n.º 4
0
 private static void CreateDbIfNotExist(IHost host)
 {
     using (IServiceScope scope = host.Services.CreateScope())
     {
         RaffleDbContext context = scope.ServiceProvider.GetRequiredService <RaffleDbContext>();
         DbInitializer.InitializeRaffle(context);
     }
 }
Ejemplo n.º 5
0
        public async void EntryAddedToDB()
        {
            RaffleDbContext     context    = getDb("DBTest");
            RaffleApiController controller = new RaffleApiController(
                context,
                getMockValidator(true));

            await controller.PostRaffleEntry(new RaffleEntry());

            Assert.Equal(1, await context.Entries.CountAsync());
        }
Ejemplo n.º 6
0
        public async void TestMoreThanTwoEntriesSerial()
        {
            options = new DbContextOptionsBuilder <RaffleDbContext>()
                      .UseInMemoryDatabase(databaseName: "TestSerialEnteredTwoTimesDatabase").Options;
            RaffleDbContext  context    = new RaffleDbContext(options);
            RaffleController controller = new RaffleController(context);

            context.Serialnumbers.Add(new Serialnumber {
                Number = 1754
            });
            context.Raffle.Add(new Raffle
            {
                Firstname = "Jane",
                Lastname  = "Doe",
                Age       = 20,
                Number    = 1754,
                Email     = "*****@*****.**"
            });
            context.Raffle.Add(new Raffle
            {
                Firstname = "John",
                Lastname  = "Doe",
                Age       = 20,
                Number    = 1754,
                Email     = "*****@*****.**"
            });

            Raffle rafSerial = new Raffle
            {
                Firstname = "Bobby",
                Lastname  = "Doe",
                Age       = 20,
                Number    = 1754,
                Email     = "*****@*****.**"
            };

            context.SaveChanges();
            var result = await controller.Create(rafSerial);


            Assert.True(context.Raffle.Where(r => r.Number.Equals(rafSerial.Number)).Count() == 2, "Entry was added, with serial that has been entered in the raffle two times");
        }
Ejemplo n.º 7
0
 public HomeController(ILogger <HomeController> logger, RaffleDbContext context)
 {
     _logger  = logger;
     _context = context;
 }
Ejemplo n.º 8
0
 public RaffleController(RaffleDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 9
0
 public RaffleApiController(RaffleDbContext context, IEntryValidator validator)
 {
     _context   = context;
     _validator = validator;
 }
Ejemplo n.º 10
0
 public HomeController(RaffleDbContext raffleDbContext, ILogger <HomeController> logger)
 {
     _raffleDbContext = raffleDbContext;
     _logger          = logger;
 }