Esempio n. 1
0
        public void Test8(Mock <IUsersService> mock)
        {
            // Arrange
            var valid = new Fixture().Build <User>()
                        .With(x => x.Id, 1)
                        .Without(x => x.Company)
                        .Without(x => x.LanguageUsers)
                        .Without(x => x.UserData)
                        .Without(x => x.Role)
                        .Create();
            bool outVal = false;

            mock.Setup(x => x.GetUser(1, out outVal)).Returns(valid);
            var controller = new CacheController(mock.Object, null);

            // Act
            IActionResult res = controller.GetData(1);

            // Assert
            var viewRes = Assert.IsType <ViewResult>(res);

            Assert.NotNull(viewRes.Model);
            var model = Assert.IsType <CacheGetDataModel>(viewRes.Model);

            Assert.Equal(1, model.User?.Id);
        }
Esempio n. 2
0
        public void GetDataReturnBadRequestOnBadId()
        {
            //Arrange
            var controller = new CacheController(null, null);

            // Act
            IActionResult res = controller.GetData(-1);

            // Assert
            var concreteRes = Assert.IsType <BadRequestObjectResult>(res);

            Assert.NotNull(concreteRes.Value);
        }
Esempio n. 3
0
        public void GetDataReturnNotFoundIfUserNotExists()
        {
            //Arrange
            var  mock   = new Mock <IUsersService>();
            bool outVal = false;

            mock.Setup(x => x.GetUser(1, out outVal)).Returns((User)null);
            var controller = new CacheController(mock.Object, null);

            // Act
            IActionResult res = controller.GetData(1);

            // Assert
            var concreteRes = Assert.IsType <NotFoundObjectResult>(res);

            Assert.NotNull(concreteRes.Value);
        }
        public void GetDataByType_TestMethod()
        {
            ICacheController cacheController = new CacheController();
            var mockCacheDataController      = new Mock <CacheDataController> {
                CallBase = true
            };
            const string modelText = "GetDataByType";
            var          cacheData = new TestCacheData {
                Model = modelText
            };

            mockCacheDataController.Object.Initialize(cacheData);

            cacheController.Add(mockCacheDataController.Object);
            var result = cacheController.GetData(typeof(TestCacheData)).First();

            var model = result.Data as TestCacheData;

            Assert.IsNotNull(model, "Model should not be null");
            Assert.IsTrue(model.Model.Contains(modelText));
        }
Esempio n. 5
0
        public void GetDataReturnUser()
        {
            // Arrange
            var  mock   = new Mock <IUsersService>();
            bool outVal = false;

            mock.Setup(x => x.GetUser(1, out outVal)).Returns(new User
            {
                Id = 1
            });
            var controller = new CacheController(mock.Object, null);

            // Act
            IActionResult res = controller.GetData(1);

            // Assert
            var viewRes = Assert.IsType <ViewResult>(res);

            Assert.NotNull(viewRes.Model);
            var model = Assert.IsType <CacheGetDataModel>(viewRes.Model);

            Assert.Equal(1, model.User?.Id);
        }
Esempio n. 6
0
        private static void TestInvalidateAndGetData(CacheController cache)
        {
            var invalidateCallbackRaised = false;
            Action invalidateCallback = () => { invalidateCallbackRaised = true; };
            cache.SetupInvalidateNotification(typeof(TestCacheData), CacheNotificationAction.Add, invalidateCallback);

            cache.Invalidate();

            Assert.IsTrue(invalidateCallbackRaised);

            var loadCallbackRaised = false;
            Action<LoadingStatus, int, string> loadCallback =
                (status, loadingKey, loadingMessage) => { loadCallbackRaised = true; };

            var uid = cache.SetupLoadNotification(typeof(TestCacheData), CacheNotificationAction.Add, loadCallback);

            var cacheDataController = cache.GetData(typeof(TestCacheData)).FirstOrDefault();
            Assert.IsNotNull(cacheDataController);
            var testData = cacheDataController.Data as TestCacheData;
            Assert.IsNotNull(testData);
            Assert.IsTrue(testData.Model == MODEL_DATA, "Data is incorrect");
            // Note: When we accessed cacheDataController.Data, and the data is not cached, this will force a Load
            Assert.IsTrue(loadCallbackRaised, "Load Callback should have been raised");
        }