Пример #1
0
        public void TestDeserialization()
        {
            JsonRepository<TestEntity> repo = new JsonRepository<TestEntity>();
            int id = 3;
            TestEntity te = new TestEntity(id);

            string testTitle = "Test Title";
            te.Title = testTitle;

            double testPrice = 7.15;
            te.UnitPrice = testPrice;

            AlbumCategory testCat = AlbumCategory.Pop;
            te.Category = testCat;

            int testQty = 7;
            te.Quantity = testQty;

            DateTime testDate = DateTime.Now.Date;
            te.ReleaseDate = testDate;

            repo.Save(te);

            Album a3 = repo.GetById(id);

            Assert.IsTrue(a3.Title == testTitle);
            Assert.IsTrue(a3.UnitPrice == testPrice);
            Assert.IsTrue(a3.Category == testCat);
            Assert.IsTrue(a3.Quantity == testQty);
            Assert.IsTrue(a3.ReleaseDate == testDate);

            Directory.Delete(repo.FolderPath, true);
        }
Пример #2
0
        protected override IJsonBoardPersonalPreferences GetData()
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.Board_Read_PersonalPrefs, new Dictionary <string, object> {
                { "_id", _ownerId }
            });
            var newData = JsonRepository.Execute <IJsonBoardPersonalPreferences>(TrelloAuthorization.Default, endpoint);

            return(newData);
        }
Пример #3
0
        protected override IJsonBoard GetData()
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.Board_Read_Refresh, new Dictionary <string, object> {
                { "_id", Data.Id }
            });
            var newData = JsonRepository.Execute <IJsonBoard>(Auth, endpoint);

            return(newData);
        }
Пример #4
0
        protected override async Task SubmitData(IJsonOrganization json, CancellationToken ct)
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.Organization_Write_Update, new Dictionary <string, object> {
                { "_id", Data.Id }
            });
            var newData = await JsonRepository.Execute(Auth, endpoint, json, ct);

            Merge(newData);
        }
Пример #5
0
        protected override IJsonOrganizationMembership GetData()
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.OrganizationMembership_Read_Refresh, new Dictionary <string, object> {
                { "_organizationId", _ownerId }, { "_id", Data.Id }
            });
            var newData = JsonRepository.Execute <IJsonOrganizationMembership>(Auth, endpoint);

            return(newData);
        }
Пример #6
0
        protected override void SubmitData(IJsonOrganizationMembership json)
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.OrganizationMembership_Write_Update, new Dictionary <string, object> {
                { "_organizationId", _ownerId }, { "_id", Data.Id }
            });
            var newData = JsonRepository.Execute(Auth, endpoint, json);

            Merge(newData);
        }
Пример #7
0
        protected override void SubmitData(IJsonBoard json)
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.Board_Write_Update, new Dictionary <string, object> {
                { "_id", Data.Id }
            });
            var newData = JsonRepository.Execute(Auth, endpoint, json);

            Merge(newData);
        }
Пример #8
0
        protected override async Task <IJsonList> GetData(CancellationToken ct)
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.List_Read_Refresh, new Dictionary <string, object> {
                { "_id", Data.Id }
            });
            var newData = await JsonRepository.Execute <IJsonList>(Auth, endpoint, ct, CurrentParameters);

            return(newData);
        }
Пример #9
0
        public void JsonRepository_Read_Succeeds()
        {
            var recipes = new JsonRepository().Recipes;

            Assert.AreEqual(2, recipes.Count());

            var homemadePizza = recipes.Single(r => r.Id == 1);

            Assert.AreEqual("Homemade Pizza", homemadePizza.Title);
        }
Пример #10
0
        public void Repository_MatchingSection_ReturnsCorrectValue(string param, int result)
        {
            // Arrange

            // Act
            var sut = JsonRepository.TryMapTaskSection(param);

            // Assert
            sut.Should().Be(result);
        }
Пример #11
0
 /// <summary>
 /// Disables a power-up for a board.
 /// </summary>
 /// <param name="powerUp">The power-up to disble.</param>
 /// <param name="ct">(Optional) A cancellation token for async processing.</param>
 public async Task DisablePowerUp(IPowerUp powerUp, CancellationToken ct = default(CancellationToken))
 {
     var endpoint = EndpointFactory.Build(EntityRequestType.Board_Write_DisablePowerUp,
                                          new Dictionary <string, object>
     {
         { "_boardId", OwnerId },
         { "_id", OwnerId }
     });
     await JsonRepository.Execute(Auth, endpoint, ct, AdditionalParameters);
 }
Пример #12
0
        private async Task <Card> CreateCard(IJsonCard json, CancellationToken ct)
        {
            json.List    = TrelloConfiguration.JsonFactory.Create <IJsonList>();
            json.List.Id = OwnerId;

            var endpoint = EndpointFactory.Build(EntityRequestType.List_Write_AddCard);
            var newData  = await JsonRepository.Execute(Auth, endpoint, json, ct);

            return(new Card(newData, Auth));
        }
Пример #13
0
        private Card CreateCard(IJsonCard json)
        {
            json.List    = TrelloConfiguration.JsonFactory.Create <IJsonList>();
            json.List.Id = OwnerId;

            var endpoint = EndpointFactory.Build(EntityRequestType.List_Write_AddCard);
            var newData  = JsonRepository.Execute(Auth, endpoint, json);

            return(new Card(newData, Auth));
        }
        protected override async Task <IJsonBoardMembership> GetData(CancellationToken ct)
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.BoardMembership_Read_Refresh,
                                                 new Dictionary <string, object> {
                { "_boardId", _ownerId }, { "_id", Data.Id }
            });
            var newData = await JsonRepository.Execute <IJsonBoardMembership>(Auth, endpoint, ct);

            return(newData);
        }
Пример #15
0
        protected override async Task SubmitData(IJsonBoard json, CancellationToken ct)
        {
            var endpoint = EndpointFactory.Build(EntityRequestType.Board_Write_Update,
                                                 new Dictionary <string, object> {
                { "_id", Data.Id }
            });
            var newData = await JsonRepository.Execute(Auth, endpoint, json, ct);

            Merge(newData);
            Data.Prefs = BoardPreferencesContext.Data;
        }
Пример #16
0
        public void Repository_GetPolicyWithInvalidParam_ReturnsMull()
        {
            // Arrange
            var repository = new JsonRepository();

            // Act
            var sut = repository.GetPolicy(10);

            // Assert
            sut.Should().Be(null);
        }
Пример #17
0
        public void TestSave()
        {
            JsonRepository <TestEntity> repo = new JsonRepository <TestEntity>();
            int        id = 7;
            TestEntity te = new TestEntity(id);

            repo.Save(te);

            Assert.IsTrue(File.Exists(repo.MakeFullPath(id)));

            Directory.Delete(repo.FolderPath, true);
        }
Пример #18
0
        public void JsonRepository_Delete_Succeeds()
        {
            var repo     = new JsonRepository();
            var existing = repo.Recipes.Single(r => r.Id == 1);

            repo.Delete(existing)
            .SaveChanges();

            existing = repo.Recipes.SingleOrDefault(r => r.Id == 1);

            Assert.IsNull(existing);
        }
Пример #19
0
        public void Update_Test()
        {
            var entities = new Dictionary <string, TestEntityOne>
            {
                { "3c0b80ed-6542-42c0-a3df-eef2d784011f", new TestEntityOne {
                      Id = "3c0b80ed-6542-42c0-a3df-eef2d784011f", FieldA = "Field_A_1", FieldB = 101, FieldC = "Field_C_1", FieldD = false
                  } },
                { "caab946b-a155-4297-a8a6-aaaa5aedf76d", new TestEntityOne {
                      Id = "caab946b-a155-4297-a8a6-aaaa5aedf76d", FieldA = "Field_A_2", FieldB = 202, FieldC = "Field_C_2", FieldD = true
                  } },
                { "3e627ea2-27e6-48a3-9846-3f27008edd6b", new TestEntityOne {
                      Id = "3e627ea2-27e6-48a3-9846-3f27008edd6b", FieldA = "Field_A_3", FieldB = 303, FieldC = "Field_C_3", FieldD = false
                  } },
                { "77a906b7-46ca-4e9a-b94b-5cf816f4d984", new TestEntityOne {
                      Id = "77a906b7-46ca-4e9a-b94b-5cf816f4d984", FieldA = "Field_A_4", FieldB = 404, FieldC = "Field_C_4", FieldD = true
                  } },
                { "71bb8f25-cdc5-43f5-a66c-4e3dab81d2af", new TestEntityOne {
                      Id = "71bb8f25-cdc5-43f5-a66c-4e3dab81d2af", FieldA = "Field_A_6", FieldB = 606, FieldC = "Field_C_6", FieldD = false
                  } }
            };

            var uowMock = new Mock <IUnitOfWork>();

            uowMock.Setup(uow => uow.Set <TestEntityOne>()).Returns(entities);

            var repo = new JsonRepository <TestEntityOne>(uowMock.Object);

            var testEntityOne = entities["3e627ea2-27e6-48a3-9846-3f27008edd6b"];

            testEntityOne.FieldA = "Changed_1";

            var idOne = repo.Update(testEntityOne);

            Assert.IsTrue(idOne == "3e627ea2-27e6-48a3-9846-3f27008edd6b");
            var result = repo.Get("3e627ea2-27e6-48a3-9846-3f27008edd6b");

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == "3e627ea2-27e6-48a3-9846-3f27008edd6b");
            Assert.IsTrue(result.FieldA == "Changed_1");
            Assert.IsTrue(repo.All().Count() == 5);

            var testEntityTwo = new TestEntityOne {
                FieldA = "Insert_2", FieldB = 222, FieldC = "Insert_2", FieldD = false
            };
            var idTwo = repo.Update(testEntityTwo);

            Assert.IsNotNull(idTwo);
            result = repo.Get(idTwo);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == idTwo);
            Assert.IsTrue(result.FieldA == "Insert_2");
            Assert.IsTrue(repo.All().Count() == 6);
        }
Пример #20
0
        public void TestGetById()
        {
            JsonRepository<TestEntity> repo = new JsonRepository<TestEntity>();
            int id = 3;
            TestEntity te = new TestEntity(id);
            repo.Save(te);

            Album a3 = repo.GetById(id);
            Assert.IsNotNull(a3);

            Directory.Delete(repo.FolderPath, true);
        }
Пример #21
0
        public void TestGetNextId()
        {
            JsonRepository <TestEntity> repo = new JsonRepository <TestEntity>();
            int        id = 7;
            TestEntity te = new TestEntity(id);

            repo.Save(te);

            Assert.IsTrue(repo.GetNextId() == id + 1);

            Directory.Delete(repo.FolderPath, true);
        }
		internal sealed override async Task PerformRefresh(bool force, CancellationToken ct)
		{
			var endpoint = EndpointFactory.Build(EntityRequestType.Card_Read_Stickers, new Dictionary<string, object> {{"_id", OwnerId}});
			var newData = await JsonRepository.Execute<List<IJsonSticker>>(Auth, endpoint, ct, AdditionalParameters);

			Items.Clear();
			Items.AddRange(newData.Select(ja =>
				{
					var attachment = TrelloConfiguration.Cache.Find<Sticker>(ja.Id) ?? new Sticker(ja, OwnerId, Auth);
					attachment.Json = ja;
					return attachment;
				}));
		}
Пример #23
0
        private JsonRepository <TestClass, int> GetSut()
        {
            var file          = Substitute.For <IFile>();
            var jsonConverter = Substitute.For <IJsonConverter>();
            var sut           = new JsonRepository <TestClass, int>(DEFAULT_FILENAME)
            {
                File          = file,
                JsonConverter = jsonConverter
            };

            sut.LoadData();
            return(sut);
        }
Пример #24
0
        protected override async Task SubmitData(IJsonAttachment json, CancellationToken ct)
        {
            // This may make a call to get the card, but it can't be avoided.  We need its ID.
            var endpoint = EndpointFactory.Build(EntityRequestType.Attachment_Write_Update,
                                                 new Dictionary <string, object>
            {
                { "_cardId", _ownerId },
                { "_id", Data.Id },
            });
            var newData = await JsonRepository.Execute(Auth, endpoint, json, ct);

            Merge(newData);
        }
Пример #25
0
        public void Repository_GetPolicyWithValidParam_ReturnsAValue()
        {
            // Arrange
            var repository = new JsonRepository();

            // Act
            var sut = repository.GetPolicy(1);

            // Assert
            sut.Id.Should().Be(1);
            sut.Firstname.Should().Be("Ian");
            sut.Surname.Should().Be("Baker");
        }
Пример #26
0
        public void SetUp()
        {
            if (_directory.Exists)
            {
                DeleteRepositoryDirectory(_directory.FullName);
            }
            _directory.Create();
            var settings    = new JsonRepositorySettings(_directory, null);
            var gitBackuper = new GitBackuper(settings.DirectoryPath);

            _repository = new JsonRepository(settings, gitBackuper);
            _dummy      = new DummySerializable(1);
        }
Пример #27
0
        public async Task ClassName_WithGenerics()
        {
            var options = new JsonStoreOptions();

            _path = FilePathEvaluator.GetFilePath(nameof(Person));
            var store = new JsonRepository <Person, int>(options);

            await store.AddAsync(_person);

            await store.SaveChangesAsync();

            Assert.True(File.Exists(_path));
        }
        /// <summary>
        /// Creates a new comment reaction.
        /// </summary>
        /// <param name="emoji">The <see cref="Emoji"/> to add.</param>
        /// <param name="ct">(Optional) A cancellation token.</param>
        /// <returns>The <see cref="ICommentReaction"/> generated by Trello.</returns>
        public async Task <ICommentReaction> Add(Emoji emoji, CancellationToken ct = default)
        {
            var json = TrelloConfiguration.JsonFactory.Create <IJsonCommentReaction>();

            json.Emoji = emoji;

            var endpoint = EndpointFactory.Build(EntityRequestType.Action_Write_AddReaction, new Dictionary <string, object> {
                ["_id"] = OwnerId
            });
            var newData = await JsonRepository.Execute(Auth, endpoint, json, ct);

            return(new CommentReaction(newData, OwnerId, Auth));
        }
Пример #29
0
        /// <summary>
        /// Enables a power-up for a board.
        /// </summary>
        /// <param name="powerUp">The power-up to enable.</param>
        /// <param name="ct">(Optional) A cancellation token for async processing.</param>
        public async Task EnablePowerUp(IPowerUp powerUp, CancellationToken ct = default(CancellationToken))
        {
            var json = TrelloConfiguration.JsonFactory.Create <IJsonPowerUp>();

            json.Id = powerUp.Id;

            var endpoint = EndpointFactory.Build(EntityRequestType.Board_Write_EnablePowerUp,
                                                 new Dictionary <string, object>
            {
                { "_id", OwnerId }
            });
            await JsonRepository.Execute(Auth, endpoint, json, ct);
        }
Пример #30
0
        public void Single_Should_Return_Correct_Entity_By_Key()
        {
            // arrange
            const string title = "Top 10 C# Tips";
            var entry = new Entry { Title = title };
            var jsonRepository = new JsonRepository(TestContext.TestDir);

            // act
            jsonRepository.Save(entry);
            var retrievedEntry = jsonRepository.Single<Entry>("top-10-c-tips");

            // assert
            Assert.AreEqual(retrievedEntry.Title, title);
        }
Пример #31
0
        /// <summary>
        /// Adds a <see cref="Sticker"/> to a <see cref="Member"/>'s custom sticker set by uploading data.
        /// </summary>
        /// <param name="data">The byte data of the file to attach.</param>
        /// <param name="name">A name for the attachment.</param>
        /// <returns>The attachment generated by Trello.</returns>
        public Sticker Add(byte[] data, string name)
        {
            var parameters = new Dictionary <string, object> {
                { RestFile.ParameterKey, new RestFile {
                      ContentBytes = data, FileName = name
                  } }
            };
            var endpoint = EndpointFactory.Build(EntityRequestType.Card_Write_AddAttachment, new Dictionary <string, object> {
                { "_id", OwnerId }
            });
            var newData = JsonRepository.Execute <IJsonSticker>(Auth, endpoint, parameters);

            return(new Sticker(newData, OwnerId, Auth));
        }
Пример #32
0
        public string Create(ICanWebhook target, string description, string callBackUrl)
        {
            var json = TrelloConfiguration.JsonFactory.Create <IJsonWebhook>();

            json.IdModel     = target.Id;
            json.Description = description;
            json.CallbackUrl = callBackUrl;

            var endpoint = EndpointFactory.Build(EntityRequestType.Webhook_Write_Entity);
            var data     = JsonRepository.Execute(Auth, endpoint, json);

            Merge(data);
            return(data.Id);
        }
Пример #33
0
        /// <summary>
        /// Removes a member from a board.
        /// </summary>
        /// <param name="member">The member to remove.</param>
        /// <param name="ct">(Optional) A cancellation token for async processing.</param>
        public async Task Remove(IMember member, CancellationToken ct = default(CancellationToken))
        {
            var error = NotNullRule <IMember> .Instance.Validate(null, member);

            if (error != null)
            {
                throw new ValidationException <IMember>(member, new[] { error });
            }

            var endpoint = EndpointFactory.Build(EntityRequestType.Board_Write_RemoveMember, new Dictionary <string, object> {
                { "_id", OwnerId }, { "_memberId", member.Id }
            });
            await JsonRepository.Execute(Auth, endpoint, ct);
        }
        public SyncService()
        {
            var channelRepository = new MemoryRepository<Channel>(new ChannelEqualityComparer());
            var playlistRepository = new MemoryRepository<Playlist>(new PlaylistEqualityComparer());
            var playlistItemsRepository = new MemoryRepository<PlaylistItem>(new PlaylistItemEqualityComparer());
            var channelPlaylistsRepository = new JsonRepository<ChannelPlaylistLink>(
                new ChannelPlaylistLinkEqualityComparer(),
                @"Cache/channels_playlists_map.json");

            _unitOfWork = new UnitOfWork(
                channelRepository,
                playlistRepository,
                playlistItemsRepository,
                channelPlaylistsRepository);
        }
Пример #35
0
        public void List_Should_Return_All_Entities()
        {
            // arrange
            var jsonRepository = new JsonRepository(TestContext.TestDir);
            jsonRepository.DeleteAll<Entry>();
            jsonRepository.Save(new Entry { Title = "Entry 1" });
            jsonRepository.Save(new Entry { Title = "Entry 2" });
            jsonRepository.Save(new Entry { Title = "Entry 3" });

            // act
            var all = jsonRepository.All<Entry>();

            // assert
            Assert.IsTrue(all.Count() == 3);
        }
Пример #36
0
        public void TestGetAll()
        {
            JsonRepository<TestEntity> repo = new JsonRepository<TestEntity>();
            int id = 1;
            TestEntity te = new TestEntity(id);
            repo.Save(te);

            id = 2;
            te = new TestEntity(id);
            repo.Save(te);

            id = 3;
            te = new TestEntity(id);
            repo.Save(te);

            repo = new JsonRepository<TestEntity>();
            var fromFiles = repo.GetAll().ToList();

            Assert.IsTrue(fromFiles.Count == 3);

            Directory.Delete(repo.FolderPath, true);
        }
Пример #37
0
        public void DoSave()
        {
            int i = SelectedAlbum.ID;

            // the actual save to local folder of json files
            JsonRepository<Album> repo = new JsonRepository<Album>();
            repo.Save(SelectedAlbum);

            SelectedAlbum = null;
            IsEditMode = false;
            _originalValues = null;
            _isNew = false;
        }
Пример #38
0
        public void TestSave()
        {
            JsonRepository<TestEntity> repo = new JsonRepository<TestEntity>();
            int id = 7;
            TestEntity te = new TestEntity(id);
            repo.Save(te);

            Assert.IsTrue(File.Exists(repo.MakeFullPath(id)));

            Directory.Delete(repo.FolderPath, true);
        }
Пример #39
0
        public void TestSearchFor()
        {
            JsonRepository<TestEntity> repo = new JsonRepository<TestEntity>();
            int id = 1;
            TestEntity te = new TestEntity(id);
            te.Quantity = 10;
            te.Category = AlbumCategory.Rock;
            te.VendorId = "FM";

            repo.Save(te);

            id = 2;
            te = new TestEntity(id);
            te.Quantity = 40;
            te.Category = AlbumCategory.Country;
            te.VendorId = "FM";
            repo.Save(te);

            id = 3;
            te = new TestEntity(id);
            te.Quantity = 10;
            te.Category = AlbumCategory.Pop;
            te.VendorId = "AMZ";
            repo.Save(te);

            repo = new JsonRepository<TestEntity>(); // start fresh

            var rslt = repo.SearchFor(a => a.VendorId == "FM").ToList();
            Assert.IsTrue(rslt.Count == 2);

            var rslt2 = repo.SearchFor(a => a.Category == AlbumCategory.Country).ToList();
            Assert.IsTrue(rslt2.Count == 1);

            var rslt3 = repo.SearchFor(a => a.Quantity > 5).ToList();
            Assert.IsTrue(rslt3.Count == 3);

            Directory.Delete(repo.FolderPath, true);
        }
Пример #40
0
        public void TestGetNextId()
        {
            JsonRepository<TestEntity> repo = new JsonRepository<TestEntity>();
            int id = 7;
            TestEntity te = new TestEntity(id);
            repo.Save(te);

            Assert.IsTrue(repo.GetNextId() == id + 1);

            Directory.Delete(repo.FolderPath, true);
        }
        public string CallGetTablesUpdate(string _tableName, string _maxJson)
        {
            string MSJ = "";
            string nameService = "GetTablesUpdate";
            var client = new RestClient(routeServiceDownLoad);
            client.Authenticator = new HttpBasicAuthenticator(basicAuthUser, basicAuthPass);
            var request = new RestRequest(Method.POST);
            request.Resource = nameService;
            request.RequestFormat = RestSharp.DataFormat.Json;
            request.AddHeader("Content-type", "application/json");
            request.AddBody(new { tableName = _tableName, maxJson = _maxJson });
            try
            {
                IRestResponse response = client.Execute(request);
                var content = response.Content;

                JsonRepository _JsonRepository = new JsonRepository();
                Dictionary<string, string> resx = _JsonRepository.GetResponseDictionary(response.Content);

                //inserta o actualiza los registros correspondientes
                MSJ = _JsonRepository.GetDeserialize(resx["GetTablesUpdateResult"], _tableName);

            }
            catch (Exception)
            {

                throw;
            }
            return MSJ;
        }