Пример #1
0
        public async void Details_ReturnsNotFound()
        {
            // Arrange
            options = new DbContextOptionsBuilder <VitecContext>()
                      .UseInMemoryDatabase(databaseName: "DetailsNotFoundSubsriberDatabase").Options;
            VitecContext context = new VitecContext(options);

            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Kenni",
                LastName    = "Bobber",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**",
                ID          = 1
            });
            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Nidolaj",
                LastName    = "Molle",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**",
                ID          = 2
            });
            context.SaveChanges();
            SubscriberController controller = new SubscriberController(context);

            // Act
            IActionResult result = await controller.Details(6);

            Assert.IsType <NotFoundResult>(result);
        }
Пример #2
0
        public async void Details_ReturnsRequested_Model()
        {
            // Arrange
            options = new DbContextOptionsBuilder <VitecContext>()
                      .UseInMemoryDatabase(databaseName: "DetailsSubsriberDatabase").Options;
            VitecContext context = new VitecContext(options);

            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Kenni",
                LastName    = "Bobber",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**",
                ID          = 1
            });
            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Nidolaj",
                LastName    = "Molle",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**",
                ID          = 2
            });
            context.SaveChanges();
            SubscriberController controller = new SubscriberController(context);

            // Act
            IActionResult result = await controller.Details(2);

            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            // Assert that it's a subscriber as model
            Subscriber sub = Assert.IsAssignableFrom <Subscriber>(viewResult.ViewData.Model);

            // Assert that it's the correct subsriber
            Assert.Equal("Nidolaj", sub.FirstName);
        }