public async Task SynchronizeForThemeAndSubtheme_BricksetApiServiceReturnsListOfSets_AllSetsAreSaved() { var themesList = JsonConvert.DeserializeObject <List <Themes> >(GetResultFileFromResource(Constants.JsonFileGetThemes)); var testTheme = themesList.First(themes => themes.Theme == Constants.TestThemeArchitecture); var yearsList = JsonConvert.DeserializeObject <List <Years> >(GetResultFileFromResource(Constants.JsonFileGetYears)); var subthemesList = JsonConvert.DeserializeObject <List <Subthemes> >(GetResultFileFromResource(Constants.JsonFileGetSubthemes)); var setsList = JsonConvert.DeserializeObject <List <Sets> >(GetResultFileFromResource(Constants.JsonFileGetSets)); var testSet = setsList.First(set => set.SetId == Constants.TestSetId); var additionalImagesList = JsonConvert.DeserializeObject <List <SetImage> >(GetResultFileFromResource(Constants.JsonFileGetAdditionalImages)); var instructionsList = JsonConvert.DeserializeObject <List <Instructions> >(GetResultFileFromResource(Constants.JsonFileGetInstructions)); var testSubtheme = subthemesList.First(bricksetSubtheme => bricksetSubtheme.Subtheme == testSet.Subtheme); var theme = testTheme.ToTheme(); theme.SetCountPerYear = yearsList.ToYearSetCountEnumerable().ToList(); _themeRepository.AddOrUpdate(theme); foreach (var subthemeItem in subthemesList) { var subthemeTheme = subthemeItem.ToSubtheme(); subthemeTheme.Theme = theme; _subthemeRepository.AddOrUpdate(subthemeTheme); } var subtheme = testSubtheme.ToSubtheme(); subtheme.Theme = theme; var bricksetApiService = Substitute.For <IBricksetApiService>(); bricksetApiService .GetSets(Arg.Any <GetSetsParameters>()) .Returns(ret => setsList.Where(setFromList => setFromList.Year == ((GetSetsParameters)ret.Args()[0]).Year && setFromList.Theme == ((GetSetsParameters)ret.Args()[0]).Theme && setFromList.Subtheme == ((GetSetsParameters)ret.Args()[0]).Subtheme)); bricksetApiService .GetAdditionalImages(Arg.Is <ParameterSetId>(parameter => parameter.SetID == testSet.SetId)) .Returns(additionalImagesList); bricksetApiService .GetInstructions(Arg.Is <ParameterSetId>(parameter => parameter.SetID == testSet.SetId)) .Returns(instructionsList); var setSynchronizer = CreateTarget(bricksetApiService); await setSynchronizer.Synchronize(string.Empty, theme, subtheme).ConfigureAwait(false); var expectedSets = setsList.Where(bricksetSets => bricksetSets.Subtheme == subtheme.Name).ToList(); Check.That(_setRepository.All()).CountIs(expectedSets.Count); var persistedSet = _setRepository.Get(testSet.SetId); Check.That(persistedSet.Images).CountIs(additionalImagesList.Count); Check.That(persistedSet.Instructions).CountIs(instructionsList.Count); }
private async Task <IEnumerable <BricksetUserSet> > GetAllUserSetsFromBrickset(string apiKey, string username = null, string userHash = null) { var allUserSets = await GetAllOwnedSets(apiKey, username, userHash).ConfigureAwait(false); var allWantedSetIds = await GetAllWantedSetIds(apiKey, username, userHash).ConfigureAwait(false); foreach (var wantedSetId in allWantedSetIds) { if (allUserSets.ContainsKey(wantedSetId)) { allUserSets[wantedSetId].Wanted = true; } else { allUserSets.Add(wantedSetId, new BricksetUserSet { Set = _setRepository.Get(wantedSetId), Wanted = true }); } } return(allUserSets.Values); }
public void Get_InvalidSetId_ReturnsNull() { var set = _setRepository.Get(0); Check.That(set).IsNull(); }
public Set Get(int id) { return(_setRepository.Get(id)); }