Esempio n. 1
0
 public static async Task <UserDto> GetUserByUserName(this IODataClient client, string userName)
 {
     return((await client.Controller <UsersController, UserDto>()
             .Function(nameof(UsersController.GetAllUsers))
             .Filter(u => u.UserName.ToLower().Contains(userName.ToLower()))
             .FindEntriesAsync()).Single());
 }
Esempio n. 2
0
        public virtual async Task PushFromSomeUserToAnotherUserUsingWebApiAndBackgroundJobWorker()
        {
            using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment())
            {
                TokenResponse tokenOfUser1 = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner");

                TokenResponse tokenOfUser2 = await testEnvironment.Server.Login("User2", "ValidPassword", clientId : "TestResOwner");

                IODataClient odataClientOfUser1 = testEnvironment.Server.BuildODataClient(token: tokenOfUser1);

                TaskCompletionSource <bool> onMessageReceivedCalled = new TaskCompletionSource <bool>();

                await testEnvironment.Server.BuildSignalRClient(tokenOfUser2, (messageKey, messageArgs) =>
                {
                    onMessageReceivedCalled.SetResult(true);
                });

                await odataClientOfUser1.Controller <TestModelsController, TestModel>()
                .Action(nameof(TestModelsController.PushSomeWordToAnotherUsingBackgroundJobWorker))
                .Set(new TestModelsController.WordParameters {
                    to = "User2", word = "Some word"
                })
                .ExecuteAsync();

                Assert.AreEqual(true, await onMessageReceivedCalled.Task);
            }
        }
Esempio n. 3
0
        public virtual async Task TestTimeZonesInCustomActionsWithClientDemand()
        {
            IValueChecker valueChecker = A.Fake <IValueChecker>();

            using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment(new TestEnvironmentArgs
            {
                AdditionalDependencies = (manager, services) =>
                {
                    manager.RegisterInstance(valueChecker);
                }
            }))
            {
                TokenResponse token = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner");

                IODataClient client = testEnvironment.Server.BuildODataClient(token: token, beforeRequest: message =>
                {
                    message.Headers.Add("Desired-Time-Zone", "Iran Standard Time");
                    message.Headers.Add("Current-Time-Zone", "Afghanistan Standard Time");
                });

                DateTimeOffset date = new DateTimeOffset(2016, 1, 1, 10, 30, 0, TimeSpan.Zero);

                await client.Controller <TestModelsController, TestModel>()
                .Action(nameof(TestModelsController.TimeZoneTests))
                .Set(new TestModelsController.TimeZoneTestsParameters
                {
                    simpleDate = date,
                    datesArray = new[] { date, date },
                    simpleDto  = new TestModel {
                        StringProperty = " ", DateProperty = date, Id = 1, Version = 1
                    },
                    entitiesArray = new[]
                    {
                        new TestModel
                        {
                            StringProperty = " ", DateProperty = date, Id = 2, Version = 2
                        },
                        new TestModel
                        {
                            StringProperty = " ", DateProperty = date, Id = 3, Version = 3
                        }
                    }
                }).ExecuteAsync();

                A.CallTo(() => valueChecker.CheckValue(A <DateTimeOffset> .That.Matches(dt => dt.Year == 2016)))
                .MustHaveHappenedOnceExactly();

                A.CallTo(() => valueChecker.CheckValue(A <List <DateTimeOffset> > .That.Matches(dates => dates.SequenceEqual(new List <DateTimeOffset> {
                    date.AddHours(1), date.AddHours(1)
                }))))
                .MustHaveHappenedOnceExactly();

                A.CallTo(() => valueChecker.CheckValue(A <TestModel> .That.Matches(tm => tm.DateProperty == date.AddHours(1))))
                .MustHaveHappenedOnceExactly();

                A.CallTo(() => valueChecker.CheckValue(A <List <TestModel> > .That.Matches(tms => tms.First().DateProperty == date.AddHours(1) && tms.Last().DateProperty == date.AddHours(1))))
                .MustHaveHappenedOnceExactly();
            }
        }
        public async Task SendEmailUsingBackgroundJobWorkerAndWebApi()
        {
            IEmailService emailService = A.Fake <IEmailService>();

            TaskCompletionSource <bool> emailSent = new TaskCompletionSource <bool>();

            A.CallTo(() => emailService.SendEmail(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored))
            .Invokes(() =>
            {
                emailSent.SetResult(true);
            });

            using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment(new TestEnvironmentArgs
            {
                AdditionalDependencies = (manager, services) =>
                {
                    manager.RegisterInstance(emailService);
                }
            }))
            {
                Token token = await testEnvironment.Server.LoginWithCredentials("ValidUserName", "ValidPassword", clientId : "TestResOwner");

                IODataClient client = testEnvironment.BuildTestODataClient(token: token);

                string jobId = (await client.TestModels()
                                .SendEmailUsingBackgroundJobService("Someone", "Email title", "Email message")
                                .ExecuteAsScalarAsync <Guid>()).ToString();

                IODataClient bitODataClient = testEnvironment.BuildBitODataClient(token: token);

                JobInfoDto jobInfo = await bitODataClient.Controller <JobsInfoController, JobInfoDto>()
                                     .Key(jobId)
                                     .FindEntryAsync();

                Assert.AreEqual(true, await emailSent.Task);

                await Task.Delay(TimeSpan.FromSeconds(1));

                jobInfo = await bitODataClient.Controller <JobsInfoController, JobInfoDto>()
                          .Key(jobId)
                          .FindEntryAsync();

                Assert.AreEqual("Succeeded", jobInfo.State);
            }
        }
Esempio n. 5
0
        public virtual async Task CustomActionMethodWithQueryableOfEntitiesReturnValueTest()
        {
            using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment())
            {
                TokenResponse token = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner");

                IODataClient client = testEnvironment.Server.BuildODataClient(token: token);

                await client.Controller <TestModelsController, TestModel>()
                .Function(nameof(TestModelsController.CustomActionMethodWithQueryableOfEntitiesReturnValueTest))
                .FindEntriesAsync();
            }
        }
Esempio n. 6
0
        public virtual async Task TestTimeZonesInUrlWithoutClientDemand()
        {
            using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment())
            {
                TokenResponse token = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner");

                IODataClient client = testEnvironment.Server.BuildODataClient(token: token);

                IEnumerable <TestModel> testModels = await client.Controller <TestModelsController, TestModel>()
                                                     .Where(tm => tm.DateProperty == new DateTimeOffset(2016, 1, 1, 10, 30, 0, TimeSpan.Zero))
                                                     .FindEntriesAsync();

                Assert.AreEqual(1, testModels.Count());
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Registers new user. If userName gets provided, it uses that for registration. Otherwise, it creates random user name.
        /// </summary>
        /// <returns>UserName. Useful when you've not provided fixed user name, so you can retrive generated user name's value.</returns>
        public static async Task <string> RegisterNewUser(this ToDoLineTestEnv testEnv, string userName = null)
        {
            userName = userName ?? Guid.NewGuid().ToString("N");

            IODataClient client = testEnv.Server.BuildODataClient(odataRouteName: "ToDoLine");

            await client.Controller <UserRegistrationController, UserRegistrationDto>()
            .Action(nameof(UserRegistrationController.Register))
            .Set(new UserRegistrationController.RegisterArgs {
                userRegistration = new UserRegistrationDto {
                    UserName = userName, Password = "******"
                }
            })
            .ExecuteAsync();

            return(userName);
        }
Esempio n. 8
0
        public virtual async Task TestTimeZonesInUrlWithClientDemand()
        {
            using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment())
            {
                TokenResponse token = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner");

                IODataClient client = testEnvironment.Server.BuildODataClient(token: token, beforeRequest: message =>
                {
                    message.Headers.Add("Desired-Time-Zone", "Iran Standard Time");
                    message.Headers.Add("Current-Time-Zone", "Afghanistan Standard Time");
                });

                IEnumerable <TestModel> testModels = await client.Controller <TestModelsController, TestModel>()
                                                     .Where(tm => tm.DateProperty == new DateTimeOffset(2016, 1, 1, 9, 30, 0, TimeSpan.Zero))
                                                     .FindEntriesAsync();

                Assert.AreEqual(1, testModels.Count());
            }
        }