Exemple #1
0
        public Task TestGetSetAsync()
        {
            var mockInstallationIdController = new Mock <IInstallationIdController>();
            var guid = Guid.NewGuid();

            mockInstallationIdController.Setup(obj => obj.Get()).Returns(guid);

            var controller   = new ParseCurrentInstallationController(mockInstallationIdController.Object);
            var installation = new ParseInstallation();

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

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

                controller.ClearFromMemory();
                Assert.AreNotEqual(installation, controller.CurrentInstallation);

                return controller.GetAsync(CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.AreNotSame(installation, controller.CurrentInstallation);
                Assert.IsNotNull(controller.CurrentInstallation);
            }));
        }
Exemple #2
0
        public Task TestIsCurrent()
        {
            var mockInstallationIdController = new Mock <IInstallationIdController>();
            var guid = Guid.NewGuid();

            mockInstallationIdController.Setup(obj => obj.Get()).Returns(guid);

            var controller    = new ParseCurrentInstallationController(mockInstallationIdController.Object);
            var installation  = new ParseInstallation();
            var installation2 = new ParseInstallation();

            return(controller.SetAsync(installation, CancellationToken.None).OnSuccess(t => {
                Assert.IsTrue(controller.IsCurrent(installation));
                Assert.IsFalse(controller.IsCurrent(installation2));

                controller.ClearFromMemory();

                Assert.IsFalse(controller.IsCurrent(installation));

                return controller.SetAsync(installation, CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.IsTrue(controller.IsCurrent(installation));
                Assert.IsFalse(controller.IsCurrent(installation2));

                controller.ClearFromDisk();

                Assert.IsFalse(controller.IsCurrent(installation));

                return controller.SetAsync(installation2, CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.IsFalse(controller.IsCurrent(installation));
                Assert.IsTrue(controller.IsCurrent(installation2));
            }));
        }