Esempio n. 1
0
        public void Test_GetPreviousFileAsync_NoPrevious()
        {
            // the blobClient in the real storage provider should return null if the blob.Exists() function is false

            IStorageProvider mockStorageProvider = new MockStorageProviderReadBlobDoesNotExist();
            var changeNumber = "3"; // needs to be valid
            var result       = AzureIpFileFunctions.GetPreviousFileAsync(mockStorageProvider, "demo", changeNumber).Result;

            // no previous expect null
            Assert.Null(result);
        }
Esempio n. 2
0
        public void Test_CompareFiles_PreviousMustHaveListValues()
        {
            var file = new ServiceTagFile()
            {
                Values = new List <ServiceTagResult>()
                {
                    new ServiceTagResult {
                        Name = "Test"
                    }
                }
            };

            Assert.Throws <Exception>(() => AzureIpFileFunctions.CompareFiles(file, new ServiceTagFile()));
        }
Esempio n. 3
0
        public void Test_CompareFiles_NoPrior_ExpectCurrent()
        {
            var file = new ServiceTagFile()
            {
                Values = new List <ServiceTagResult>()
                {
                    new ServiceTagResult {
                        Name = "Test"
                    }
                }
            };
            var delta = AzureIpFileFunctions.CompareFiles(file, null);

            Assert.Equal(delta.Count == 1 && delta[0].Name == "Test", true);
        }
Esempio n. 4
0
        public void Test_GetPreviousFileAsync_Previous_TooOld()
        {
            // the function should look for a file named previous change number, even if there's a gap, so here "1"
            var file = new ServiceTagFile()
            {
                ChangeNumber = "1"
            };
            var fileAsStream = AzureIpFileFunctions.StringToStream(AzureIpFileFunctions.SerializeFile(file));

            IStorageProvider mockStorageProvider = new MockStorageProviderReadBlobDoesExist(fileAsStream, "1");

            var changeNumber = "4"; // needs to be valid
            // expect file "1" - but implementation only goes back 2, so null
            var result = AzureIpFileFunctions.GetPreviousFileAsync(mockStorageProvider, "demo", changeNumber).Result;

            // found nothing
            Assert.Null(result);
        }
Esempio n. 5
0
        public void Test_GetPreviousFileAsync_Previous_NonContiguous()
        {
            // the function should look for a file named previous change number, even if there's a gap, so here "1"
            var file = new ServiceTagFile()
            {
                ChangeNumber = "2"
            };
            var fileAsStream = AzureIpFileFunctions.StringToStream(AzureIpFileFunctions.SerializeFile(file));

            IStorageProvider mockStorageProvider = new MockStorageProviderReadBlobDoesExist(fileAsStream, "2");

            var changeNumber = "4"; // needs to be valid
            // expect file "2"
            var result = AzureIpFileFunctions.GetPreviousFileAsync(mockStorageProvider, "demo", changeNumber).Result;

            // found previous
            Assert.Equal(result.ChangeNumber, file.ChangeNumber);
        }
Esempio n. 6
0
        public void Test_CompareChangeNumbers_true()
        {
            var current = new ServiceTagResult()
            {
                Properties = new ServiceTagProperties()
                {
                    ChangeNumber = "2"
                }
            };
            var prior = new ServiceTagResult()
            {
                Properties = new ServiceTagProperties()
                {
                    ChangeNumber = "1"
                }
            };

            var result = AzureIpFileFunctions.CompareChangeNumbers(current, prior);

            Assert.Equal(result, true);
        }
Esempio n. 7
0
        public void Test_CompareFiles_DeltaIsLatest()
        {
            // old
            var prior = new ServiceTagFile()
            {
                Values = new List <ServiceTagResult>()
            };

            prior.Values.Add(new ServiceTagResult()
            {
                Id = "a", Properties = new ServiceTagProperties()
                {
                    ChangeNumber = "9"
                }
            });
            prior.Values.Add(new ServiceTagResult()
            {
                Id = "b", Properties = new ServiceTagProperties()
                {
                    ChangeNumber = "9"
                }
            });

            //newer
            var current = new ServiceTagFile()
            {
                Values = new List <ServiceTagResult>()
            };

            current.Values.Add(new ServiceTagResult()
            {
                Id = "a", Properties = new ServiceTagProperties()
                {
                    ChangeNumber = "9"
                }
            });
            current.Values.Add(new ServiceTagResult()
            {
                Id = "b", Properties = new ServiceTagProperties()
                {
                    ChangeNumber = "10"
                }
            });
            current.Values.Add(new ServiceTagResult()
            {
                Id = "c", Properties = new ServiceTagProperties()
                {
                    ChangeNumber = "1"
                }
            });
            current.Values.Add(new ServiceTagResult()
            {
                Id = "d", Properties = new ServiceTagProperties()
                {
                    ChangeNumber = "2"
                }
            });

            var delta = AzureIpFileFunctions.CompareFiles(current, prior);

            // expect only result from current where the id matches and change number is > same id in prior
            // or the result entry is new
            Assert.Equal(delta.Count, 3);
            Assert.NotNull(delta.Single(r => r.Id == "b" && r.Properties.ChangeNumber == "10"));
            Assert.NotNull(delta.Single(r => r.Id == "c" && r.Properties.ChangeNumber == "1"));
            Assert.NotNull(delta.Single(r => r.Id == "d" && r.Properties.ChangeNumber == "2"));
        }
Esempio n. 8
0
 public void Test_CompareFiles_CurrentFileMissing()
 {
     Assert.Throws <Exception>(() => AzureIpFileFunctions.CompareFiles(null, null));
 }
Esempio n. 9
0
        public void Test_GetChangeNumber()
        {
            var changeNumber = AzureIpFileFunctions.GetChangeNumber(Sz());

            Assert.Equal(changeNumber, _ServiceTagFile.ChangeNumber);
        }