示例#1
0
        public void GivenAFailureOfLogin_TheIsProcessingStatusShouldBackToFalseAnyway()
        {
            var vm = new LoginWndVm(_clientFactory, _credentialPersist)
            {
                UserName = "******", Password = "******"
            };
            var changeCount = 0;

            vm.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == PropertyName.Get((LoginWndVm v) => v.IsProcessing))
                {
                    changeCount++;
                }
            };

            _clientFactory.When(x => x.Login(Arg.Any <string>(), Arg.Any <string>())).Do(x => { throw new Exception(); });

            Assert.Throws <Exception>(async() =>
            {
                await vm.Login();
            });

            _clientFactory.Received(1).Login(vm.UserName, vm.Password).IgnoreAsyncWarning();

            Assert.That(changeCount, Is.EqualTo(2), "IsProcessing should be changed twice, first it's changed to busy, and then back to false.");
            Assert.False(vm.IsProcessing, "Status should back to non-busy");
        }
        public async Task CreateUser_With_Duplicated_Email_Should_Return_Validation_Error()
        {
            var response = await Some.UserService(Some.MockedContext().With(Some.User().With(userName: "******", email: "*****@*****.**").ToList()))
                           .CreateUserAsync(Some.CreateUserCommand().With(userName: "******", email: "*****@*****.**"));

            response.ValidationResult.Errors.Should().ContainKey(PropertyName.Get((CreateUserCommand x) => x.Email));
        }
示例#3
0
        protected override void Execute(NativeActivityContext context)
        {
            var source       = SourceList.Get(context);
            var propertyName = PropertyName.Get(context);
            var properties   = TypeDescriptor.GetProperties(typeof(T));
            var property     = properties.Cast <PropertyDescriptor>().FirstOrDefault(i => i.Name.Equals(propertyName, System.StringComparison.InvariantCultureIgnoreCase));

            if (property == null)
            {
                throw new DeveloperException("Задан не верный параметр {0}", propertyName);
            }
            var sum = source.Sum(o => Convert.ToInt32(property.GetValue(o)));

            context.SetValue(Result, sum);
        }
示例#4
0
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments
            // Specified ClassName cannot be WhiteSpace or NULL
            //
            if (ClassName.Expression != null && !string.IsNullOrWhiteSpace(ClassName.Get(context)))
            {
                targetCommand.AddParameter("ClassName", ClassName.Get(context));
            }

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (MethodName.Expression != null)
            {
                targetCommand.AddParameter("MethodName", MethodName.Get(context));
            }

            if (PropertyName.Expression != null)
            {
                targetCommand.AddParameter("PropertyName", PropertyName.Get(context));
            }

            if (QualifierName.Expression != null)
            {
                targetCommand.AddParameter("QualifierName", QualifierName.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
示例#5
0
        public async void ShouldChangeTheIsProcessingStatusWhenLogin()
        {
            var vm = new LoginWndVm(_clientFactory, _credentialPersist)
            {
                UserName = "******", Password = "******"
            };
            var changeCount = 0;

            vm.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == PropertyName.Get((LoginWndVm v) => v.IsProcessing))
                {
                    changeCount++;
                }
            };
            await vm.Login();

            _clientFactory.Received(1).Login(vm.UserName, vm.Password).IgnoreAsyncWarning();

            Assert.That(changeCount, Is.EqualTo(2), "IsProcessing should be changed twice, first it's changed to busy, and then back to false.");
            Assert.False(vm.IsProcessing, "Status should back to non-busy");
        }
示例#6
0
        protected override void Execute(NativeActivityContext context)
        {
            var prModel = new PropertyModel(PropertyName.Get(context), typeof(T), Description.Get(context), RequiresInitialization.Get(context), MarkRequiredInBuilder.Get(context));

            ((ClassModel)context.Properties.Find("ClassModel")).AddProperty(prModel);
        }
        public async Task CreateUser_With_Incorrectly_Repeated_Password_Should_Return_Validation_Error()
        {
            var response = await Some.UserService().CreateUserAsync(Some.CreateUserCommand().With(password: "******", rePassword: "******"));

            response.ValidationResult.Errors.Should().ContainKey(PropertyName.Get((CreateUserCommand x) => x.RepeatedPassword));
        }
        public async Task CreateUser_Invalid_UserName_Should_Return_Validation_Error()
        {
            var response = await Some.UserService().CreateUserAsync(Some.CreateUserCommand().With(userName: "******"));

            response.ValidationResult.Errors.Should().ContainKey(PropertyName.Get((CreateUserCommand x) => x.UserName));
        }
        public async Task CreateUser_Invalid_Email_Should_Return_Validation_Error()
        {
            var response = await Some.UserService().CreateUserAsync(Some.CreateUserCommand().With(email: "invalid"));

            response.ValidationResult.Errors.Should().ContainKey(PropertyName.Get((CreateUserCommand x) => x.Email));
        }