Пример #1
0
        public Task TestGetSetAsync()
        {
            var storageController = new Mock <IStorageController>(MockBehavior.Strict);
            var mockedStorage     = new Mock <IStorageDictionary <string, object> >();
            var controller        = new AVCurrentUserController(storageController.Object);
            var user = new AVUser();

            storageController.Setup(s => s.LoadAsync()).Returns(Task.FromResult(mockedStorage.Object));

            return(controller.SetAsync(user, CancellationToken.None).OnSuccess(_ => {
                Assert.AreEqual(user, controller.CurrentUser);

                object jsonObject = null;
                Predicate <object> predicate = o => {
                    jsonObject = o;
                    return true;
                };

                mockedStorage.Verify(s => s.AddAsync("CurrentUser", Match.Create <object>(predicate)));
                mockedStorage.Setup(s => s.TryGetValue("CurrentUser", out jsonObject)).Returns(true);

                return controller.GetAsync(CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.AreEqual(user, controller.CurrentUser);

                controller.ClearFromMemory();
                Assert.AreNotEqual(user, controller.CurrentUser);

                return controller.GetAsync(CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.AreNotSame(user, controller.CurrentUser);
                Assert.IsNotNull(controller.CurrentUser);
            }));
        }
Пример #2
0
        public Task TestLogOut()
        {
            var storageController = new Mock <IStorageController>(MockBehavior.Strict);
            var controller        = new AVCurrentUserController(storageController.Object);
            var user = new AVUser();

            return(controller.SetAsync(user, CancellationToken.None).OnSuccess(_ => {
                Assert.AreEqual(user, controller.CurrentUser);
                return controller.ExistsAsync(CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.IsTrue(t.Result);

                return controller.LogOutAsync(CancellationToken.None);
            }).Unwrap().OnSuccess(_ => controller.GetAsync(CancellationToken.None)).Unwrap()
                   .OnSuccess(t => {
                Assert.IsNull(t.Result);

                return controller.ExistsAsync(CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.IsFalse(t.Result);
            }));
        }