Inheritance: IUserProfileServiceResult
        public static UserProfileResultMock Create(bool isValid, bool isExisting) {

            var result = new UserProfileResultMock();
            result.Error = (uint)(isValid ? 0 : 13);
            result.ProfileExists = isExisting;

            return result;
        }
        public static UserProfileResultMock Create(bool isValid, bool isExisting)
        {
            var result = new UserProfileResultMock();

            result.Error         = (uint)(isValid ? 0 : 13);
            result.ProfileExists = isExisting;

            return(result);
        }
Beispiel #3
0
        public IUserProfileServiceResult DeleteUserProfile(IUserCredentials credMock, ILogger logger)
        {
            if (!TestingValidParse)
            {
                // If parse succeeded but did not generate an object,
                // for example, JSON parse of white spaces.
                credMock.Should().BeNull();
                return(UserProfileResultMock.Create(false, false));
            }

            ValidateUsername(credMock?.Username);
            ValidateDomain(credMock?.Domain);
            ValidateSid(credMock?.Sid);

            return(UserProfileResultMock.Create(TestingValidAccount, TestingExistingAccount));
        }
        private async Task CreateProfileFuzzTestRunnerAsync(IUserProfileServices creator, IUserProfileNamedPipeFactory pipeFactory, string input, int serverTimeOut, int clientTimeOut)
        {
            var task = Task.Run(async() => {
                try {
                    await RUserProfileServicesHelper.CreateProfileAsync(serverTimeOutms: serverTimeOut, clientTimeOutms: clientTimeOut, userProfileService: creator, pipeFactory: pipeFactory);
                } catch (JsonReaderException) {
                    // expecting JSON parsing to fail
                    // JSON parsing may fail due to randomly generated strings as input.
                }
            });

            using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(clientTimeOut))) {
                UserProfileResultMock result = await CreateProfileClientTestWorkerAsync(input, cts.Token);

                // fuzz test parsing succeeded, the creator always fails for this test.
                result?.Error.Should().Be(13);
            }

            await ParallelTools.When(task, serverTimeOut + clientTimeOut);
        }
        private async Task CreateProfileTestRunnerAsync(IUserProfileServices creator, IUserProfileNamedPipeFactory pipeFactory, string input, bool isValidParse, bool isValidAccount, bool isExistingAccount, int serverTimeOut, int clientTimeOut)
        {
            ManualResetEventSlim testDone = new ManualResetEventSlim(false);

            Task.Run(async() => {
                try {
                    if (isValidParse)
                    {
                        Func <Task> f = async() => await RUserProfileServicesHelper.CreateProfileAsync(serverTimeOutms: serverTimeOut, clientTimeOutms: clientTimeOut, userProfileService: creator, pipeFactory: pipeFactory);
                        f.ShouldNotThrow();
                    }
                    else
                    {
                        Func <Task> f = () => RUserProfileServicesHelper.CreateProfileAsync(serverTimeOutms: serverTimeOut, clientTimeOutms: clientTimeOut, userProfileService: creator, pipeFactory: pipeFactory);
                        await f.ShouldThrowAsync <Exception>();
                    }
                } finally {
                    testDone.Set();
                }
            }).DoNotWait();

            using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(clientTimeOut))) {
                UserProfileResultMock result = await CreateProfileClientTestWorkerAsync(input, cts.Token);

                if (isValidParse)
                {
                    result.Error.Should().Be((uint)(isValidAccount ? 0 : 13));
                    result.ProfileExists.Should().Be(isExistingAccount);
                }
                else
                {
                    result.Should().BeNull();
                }
            }

            testDone.Wait(serverTimeOut + clientTimeOut);
        }
Beispiel #6
0
 public IUserProfileServiceResult DeleteUserProfile(IUserCredentials credentails, ILogger logger)
 {
     // The fuzz test generated a valid parse-able JSON for the test we fail the login
     return(UserProfileResultMock.Create(false, false));
 }