Example #1
0
        public void GetById_NotFound_Test()
        {
            // Arrange
            var mockService = new Mock <ILanguageService>();
            var controller  = new LanguageController(mockService.Object);

            // Act
            IHttpActionResult actionResult = controller.GetById(-1);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
Example #2
0
        public void GetById()
        {
            using (var scope = Factory.Services.CreateScope())
            {
                var language = new Language()
                {
                    Culture = "dj-af", Languages = "djibouti"
                };
                var languageService    = scope.ServiceProvider.GetRequiredService <ILanguageService>();
                var logger             = scope.ServiceProvider.GetRequiredService <ILogger <LanguageController> >();
                var languageController = new LanguageController(logger, languageService);

                var result = languageController.GetById(1);

                Assert.Equal(language.Languages, result.Languages);
            }
        }
Example #3
0
        public void GetById_Test()
        {
            int id = 42;

            // Arrange
            var mockService = new Mock <ILanguageService>();

            mockService.Setup(x => x.GetById(id))
            .Returns(new LanguageModel {
                Id = id
            });

            var controller = new LanguageController(mockService.Object);


            // Act
            IHttpActionResult actionResult = controller.GetById(id);
            var contentResult = actionResult as OkNegotiatedContentResult <LanguageModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(id, contentResult.Content.Id);
        }