Beispiel #1
0
        public void TestGetLanguageNotFound()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    context.Language.Add(new Language());
                    context.SaveChanges();

                    LanguageController controller = new LanguageController(context);
                    var actionResult = controller.Get(2).Result;
                    var result       = actionResult as NotFoundObjectResult;

                    Assert.IsNotNull(actionResult);
                    Assert.AreEqual(404, result.StatusCode);
                    Assert.AreEqual("No languages from given id found.", result.Value);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #2
0
        public void Test1()
        {
            var res = _languageController.Get();

            Assert.IsNotNull(res);

            // Assert.Pass();
        }
        public void Get()
        {
            LanguageController languageController = new LanguageController();

            Language[] languages = languageController.Get().ToArray();

            Assert.IsNotNull(languages);
        }
        public void GetEntitysBadRepository()
        {
            // Arrange
            var controller = new LanguageController(GetMockRepo(false));

            // Act
            var result = controller.Get(1, 1);

            // Assert
            Assert.IsType <UnprocessableEntityObjectResult>(result);
        }
        public void GetEntitysNoExist()
        {
            // Arrange
            var controller = new LanguageController(GetMockRepo());

            // Act
            var result = controller.Get(0, 0);

            // Assert
            Assert.IsType <NoContentResult>(result);
        }
        public void GetEntitysExist()
        {
            // Arrange
            var controller = new LanguageController(GetMockRepo());

            // Act
            var result = controller.Get(1, 1);

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
        public void GetEntityNoExist()
        {
            // Arrange
            var  controller = new LanguageController(GetMockRepo());
            uint id         = 0;

            // Act
            var result = controller.Get(id);

            // Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
        public void GetEntitysByName()
        {
            // Arrange
            var controller = new LanguageController(GetMockRepo());

            // Act
            var result = controller.Get(name: "tesTKey") as OkObjectResult;
            var list   = result.Value as IEnumerable;
            var amount = 0;

            foreach (var item in list)
            {
                amount++;
            }

            // Assert
            Assert.IsType <OkObjectResult>(result);
            Assert.True(amount == 1);
        }
        public void GetEntitysMaxPage()
        {
            // Arrange
            var maxAmount  = 100;
            var controller = new LanguageController(GetMockRepo(oversized: true));

            // Act
            var result = controller.Get(1, 1000) as OkObjectResult;
            var list   = result.Value as IEnumerable;
            var amount = 0;

            foreach (var item in list)
            {
                amount++;
                if (amount > maxAmount)
                {
                    break;
                }
            }

            // Assert
            Assert.IsType <OkObjectResult>(result);
            Assert.True(amount <= maxAmount);
        }