public void TryRetrieveTokenFromDatabase_UnknownId_ReturnsEmptyObject()
        {
            var userId = Guid.NewGuid();
            var data = Enumerable.Empty<UserToken>().AsQueryable();

            var fakeDbSet = SetupFakeDbSet(data);
            var fakeContext = SetupFakeDbContext(fakeDbSet);

            var sut = new UserTokenRepository(fakeContext);

            var result = sut.TryRetrieveTokenFromDatabase(userId);

            Assert.That(result, Is.EqualTo(UserToken.Empty));
        }
        public void UpdateOrCreateToken_AnyInput_CallsSaveChanges()
        {
            var userId = Guid.NewGuid();

            var data = Enumerable.Empty<UserToken>().AsQueryable();

            var fakeDbSet = SetupFakeDbSet(data);
            var fakeContext = SetupFakeDbContext(fakeDbSet);

            var sut = new UserTokenRepository(fakeContext);

            sut.UpdateOrCreateToken(userId);

            A.CallTo(() => fakeContext.SaveChanges()).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void TryRetrieveTokenFromDatabase_KnownId_ReturnsObjectFromDatabase()
        {
            var userId = Guid.NewGuid();
            var expected = new UserToken
            {
                Id = Guid.NewGuid(),
                UserId = userId,
                DropboxAccessToken = "dropbox_token",
                ExactAccessToken = "exact_token"
            };

            var data = new List<UserToken> { expected }.AsQueryable();

            var fakeDbSet = SetupFakeDbSet(data);
            var fakeContext = SetupFakeDbContext(fakeDbSet);

            var sut = new UserTokenRepository(fakeContext);

            var result = sut.TryRetrieveTokenFromDatabase(userId);

            Assert.That(result, Is.EqualTo(expected));
        }
        public void UpdateOrCreateToken_ExistingToken_UpdatesObjectWithInput()
        {
            var id = Guid.NewGuid();
            var userId = Guid.NewGuid();
            var existing = new UserToken
            {
                Id = id,
                UserId = userId,
                DropboxAccessToken = "dropbox_token",
                ExactAccessToken = "exact_token"
            };
            var expected = new UserToken
            {
                Id = id,
                UserId = userId,
                DropboxAccessToken = "new_dropbox_token",
                ExactAccessToken = "new_exact_token"
            };

            var data = new List<UserToken> { existing }.AsQueryable();

            var fakeDbSet = SetupFakeDbSet(data);
            var fakeContext = SetupFakeDbContext(fakeDbSet);

            var sut = new UserTokenRepository(fakeContext);

            sut.UpdateOrCreateToken(userId, "new_dropbox_token", "new_exact_token");

            Assert.That(existing, Is.EqualTo(expected));
        }
        public void UpdateOrCreateToken_NewToken_CreatesObject()
        {
            var userId = Guid.NewGuid();

            var data = Enumerable.Empty<UserToken>().AsQueryable();

            var fakeDbSet = SetupFakeDbSet(data);
            var fakeContext = SetupFakeDbContext(fakeDbSet);

            var sut = new UserTokenRepository(fakeContext);

            sut.UpdateOrCreateToken(userId);

            A.CallTo(() => fakeDbSet.Add(A.Dummy<UserToken>())).WithAnyArguments().MustHaveHappened(Repeated.Exactly.Once);
        }