public void FindCountryById_Action_Fails()
        {
            // Arrange
            GenericServiceResponse <CountryDto> fakeResponse = null;

            mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable();
            mockClientServicesProvider.Setup(x => x.CountryService.FindCountryById(It.IsAny <int>())).Returns(fakeResponse).Verifiable();

            var viewModel = new GenericItemViewModel <CountryDto>();

            var action = new FindCountryById <GenericItemViewModel <CountryDto> >(mockClientServicesProvider.Object)
            {
                OnComplete = model => viewModel = model
            };

            // Act
            var result = action.Invoke(1);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(GenericItemViewModel <CountryDto>));
            Assert.IsNotNull(result.Notifications);
            Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection));
            Assert.IsTrue(result.Notifications.Count() == 1);
            Assert.IsTrue(result.HasErrors);
            Assert.IsNull(result.Item);
        }
Esempio n. 2
0
        public void FindUserById_Action_Success()
        {
            // Arrange
            var fakeResponse = new GenericServiceResponse <UserDto>
            {
                Result = TestHelper.UserDto()
            };

            mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable();
            mockClientServicesProvider.Setup(x => x.UserService.FindUserById(It.IsAny <int>())).Returns(fakeResponse).Verifiable();

            var viewModel = new GenericItemViewModel <UserDto>();

            var action = new FindUserById <GenericItemViewModel <UserDto> >(mockClientServicesProvider.Object)
            {
                OnComplete = model => viewModel = model
            };

            // Act
            var result = action.Invoke(1);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(GenericItemViewModel <UserDto>));
            Assert.IsNotNull(result.Notifications);
            Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection));
            Assert.IsTrue(result.Notifications.Count() == 0);
            Assert.IsFalse(result.HasErrors);
            Assert.IsNotNull(result.Item);
            Assert.IsInstanceOfType(result.Item, typeof(UserDto));
        }
Esempio n. 3
0
        public T Invoke(int id)
        {
            return(Execute(() =>
            {
                var model = new GenericItemViewModel <EmployeeDto>();

                var serviceResult = ServiceProvider.EmployeeService.FindEmployeeById(id);

                if (serviceResult == null || serviceResult.Result == null || serviceResult.Notifications.HasErrors())
                {
                    var errorMessage = "Sorry, an unexpected error occurred.";
                    model.Notifications.AddError(errorMessage);
                }
                else
                {
                    model.Item = serviceResult.Result;
                }

                return OnComplete(model);
            }, this.GetType().Name));
        }