public void Update_AddingMultipleApprenticeshipsWithLocationsThatAlreadyExists()
        {
            var sut = new Write.ApprenticeshipFavourites
            {
                new Write.ApprenticeshipFavourite {
                    ApprenticeshipId = "ABC123", Providers = new List <Write.Provider> {
                        new Write.Provider(12345678, new List <int> {
                            1, 2, 3
                        })
                    }
                },

                new Write.ApprenticeshipFavourite {
                    ApprenticeshipId = "DEF123", Providers = new List <Write.Provider> {
                        new Write.Provider(87654321, new List <int> {
                            1, 2, 3
                        })
                    }
                }
            };

            var result = sut.Update("ABC123", new List <Basket.Provider>()
            {
                new Basket.Provider(12345678, "Test Provider")
                {
                    Locations = new List <int> {
                        1, 2, 3
                    }
                }
            });

            Assert.False(result);
        }
        public void Update_AddApprenticeship()
        {
            var sut = new Write.ApprenticeshipFavourites
            {
                new Write.ApprenticeshipFavourite {
                    ApprenticeshipId = "ABC123", Providers = new List <Write.Provider> {
                        new Write.Provider(12345678, new List <int> {
                            1, 2, 3
                        })
                    }
                }
            };

            var result = sut.Update("XYZ123", new List <Basket.Provider>()
            {
                new Basket.Provider(12345678, "Test Provider")
                {
                    Locations = new List <int> {
                        4, 5
                    }
                }
            });

            Assert.True(result);
        }
        public void Update_FromNoApprenticeshipsToAnApprenticeshipWithNoTrainingProviders()
        {
            var sut = new Write.ApprenticeshipFavourites {
            };

            var result = sut.Update("DEF123", null);

            Assert.True(result);
        }
Ejemplo n.º 4
0
 public async Task SaveApprenticeshipFavourites(string employerAccountId, WriteModel.ApprenticeshipFavourites apprenticeshipFavourites)
 {
     try
     {
         await _retryPolicy.ExecuteAsync(context => _favouritesApi.PutAsync(employerAccountId, apprenticeshipFavourites), new Context(nameof(SaveApprenticeshipFavourites)));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Unable to Save Apprenticeship Favourites to Api for Account: {employerAccountId}", employerAccountId);
         throw;
     }
 }
        private static bool ContainsAllNewApprenticeships(WriteModel.ApprenticeshipFavourites a, List <Tuple <string, string, List <int> > > newFavourites)
        {
            foreach (var item in newFavourites)
            {
                var matchingItem = a.SingleOrDefault(x => x.ApprenticeshipId == item.Item1);

                if (matchingItem == null || matchingItem.Providers == null || matchingItem.Providers.Count != item.Item3.Count)
                {
                    return(false);
                }

                for (int i = 0; i < item.Item3.Count; i++)
                {
                    if (item.Item3[i] != matchingItem.Providers[i].Ukprn)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
 public Task SaveApprenticeshipFavourites(string employerAccountId, WriteModel.ApprenticeshipFavourites apprenticeshipFavourite)
 {
     return(Task.CompletedTask);
 }
 private static bool ContainsExistingPlusNewApprenticeship(WriteModel.ApprenticeshipFavourites a, string apprenticeshipId)
 {
     return(a.Count == (GetTestRepositoryFavourites().Count + 1) && a.Any(b => b.ApprenticeshipId == apprenticeshipId));
 }
 private static bool ContainsNewUkprnForExistingApprenticeship(WriteModel.ApprenticeshipFavourites a, string apprenticeshipId, int ukprn)
 {
     return(a.Count == GetTestRepositoryFavourites().Count &&
            a.Any(b => b.ApprenticeshipId == apprenticeshipId && b.Providers.Select(c => c.Ukprn).Contains(ukprn)));
 }
 private static bool ContainsExistingAndNewApprenticeshipWithUkprn(WriteModel.ApprenticeshipFavourites a, string apprenticeshipId, int ukprn)
 {
     return(ContainsExistingPlusNewApprenticeship(a, apprenticeshipId) &&
            a.Any(b => b.ApprenticeshipId == apprenticeshipId && b.Providers.Select(c => c.Ukprn).Contains(ukprn)));
 }