public void TestLocatorDeleteRetry() { var dataContextMock = new Mock <IMediaDataServiceContext>(); int exceptionCount = 2; var locator = new LocatorData { Name = "testData", Type = (int)LocatorType.OnDemandOrigin }; var fakeResponse = new TestMediaDataServiceResponse { AsyncState = locator }; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); dataContextMock.Setup((ctxt) => ctxt.AttachTo("Locators", locator)); dataContextMock.Setup((ctxt) => ctxt.DeleteObject(locator)); dataContextMock.Setup((ctxt) => ctxt .SaveChangesAsync(locator)) .Returns(() => Task.Factory.StartNew <IMediaDataServiceResponse>(() => { if (--exceptionCount > 0) { throw fakeException; } return(fakeResponse); })); // Cannot mock DataServiceQuery. Throw artificial exception to mark pass through saving changes. string artificialExceptionMessage = "artificialException"; dataContextMock.Setup((ctxt) => ctxt.CreateQuery <IAsset, AssetData>("Assets")).Throws(new Exception(artificialExceptionMessage)); _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object); locator.SetMediaContext(_mediaContext); try { locator.Delete(); } catch (Exception x) { Assert.AreEqual(artificialExceptionMessage, x.Message); } Assert.AreEqual(0, exceptionCount); }
public QueryOperationResponse LoadProperty(object entity, string propertyName) { //Example of Load property simulation if (entity is AssetData) { AssetData assetData = (AssetData)(entity); switch (propertyName) { case "Locators": assetData.Locators = new List <LocatorData>(CreateQuery <LocatorData>("Locators").Where(c => c.AssetId == c.AssetId).ToList()); break; default: break; } } if (entity is LocatorData) { LocatorData data = (LocatorData)(entity); switch (propertyName) { case "Asset": data.Asset = CreateQuery <AssetData>("Assets").Where(c => c.Id == data.AssetId).FirstOrDefault(); break; case "AccessPolicy": data.AccessPolicy = CreateQuery <AccessPolicyData>(AccessPolicyBaseCollection.AccessPolicySet).Where(c => c.Id == data.AccessPolicyId).FirstOrDefault(); break; default: break; } } if (entity is JobTemplateData) { JobTemplateData data = (JobTemplateData)(entity); switch (propertyName) { case "TaskTemplates": data.TaskTemplates = CreateQuery <TaskTemplateData>("TaskTemplates").ToList(); break; default: break; } } return(null); }
public void TestLocatorCreateRetry() { var dataContextMock = new Mock <IMediaDataServiceContext>(); int exceptionCount = 2; var expected = new LocatorData { Name = "testData" }; var fakeResponse = new TestMediaDataServiceResponse { AsyncState = expected }; var fakeException = new WebException("testException", WebExceptionStatus.ConnectionClosed); dataContextMock.Setup((ctxt) => ctxt.AddObject("Files", It.IsAny <object>())); dataContextMock.Setup((ctxt) => ctxt .SaveChangesAsync(It.IsAny <object>())) .Returns(() => Task.Factory.StartNew <IMediaDataServiceResponse>(() => { if (--exceptionCount > 0) { throw fakeException; } return(fakeResponse); })); _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object); var asset = new AssetData { Name = "testAssetData" }; asset.SetMediaContext(_mediaContext); ILocator locator = _mediaContext.Locators.CreateLocator(LocatorType.None, asset, new AccessPolicyData()); Assert.AreEqual(expected.Name, locator.Name); Assert.AreEqual(0, exceptionCount); }
public void TestLocatorUpdateRetry() { var dataContextMock = new Mock <IMediaDataServiceContext>(); int exceptionCount = 2; var locator = new LocatorData { Name = "testData", Type = (int)LocatorType.OnDemandOrigin }; var fakeResponse = new TestMediaDataServiceResponse { AsyncState = locator }; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); dataContextMock.Setup((ctxt) => ctxt.AttachTo("Locators", locator)); dataContextMock.Setup((ctxt) => ctxt.UpdateObject(locator)); dataContextMock.Setup((ctxt) => ctxt .SaveChangesAsync(locator)) .Returns(() => Task.Factory.StartNew <IMediaDataServiceResponse>(() => { if (--exceptionCount > 0) { throw fakeException; } return(fakeResponse); })); _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object); locator.SetMediaContext(_mediaContext); locator.Update(DateTime.Now); Assert.AreEqual(0, exceptionCount); }
public void TestLocatorUpdateRetry() { var dataContextMock = new Mock<IMediaDataServiceContext>(); int exceptionCount = 2; var locator = new LocatorData { Name = "testData", Type = (int)LocatorType.OnDemandOrigin }; var fakeResponse = new TestMediaDataServiceResponse { AsyncState = locator }; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); dataContextMock.Setup((ctxt) => ctxt.AttachTo("Locators", locator)); dataContextMock.Setup((ctxt) => ctxt.UpdateObject(locator)); dataContextMock.Setup((ctxt) => ctxt .SaveChangesAsync(locator)) .Returns(() => Task.Factory.StartNew<IMediaDataServiceResponse>(() => { if (--exceptionCount > 0) throw fakeException; return fakeResponse; })); _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object); locator.SetMediaContext(_mediaContext); locator.Update(DateTime.Now); Assert.AreEqual(0, exceptionCount); }
public void TestLocatorDeleteRetry() { var dataContextMock = new Mock<IMediaDataServiceContext>(); int exceptionCount = 2; var locator = new LocatorData { Name = "testData", Type = (int)LocatorType.OnDemandOrigin }; var fakeResponse = new TestMediaDataServiceResponse { AsyncState = locator }; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); dataContextMock.Setup((ctxt) => ctxt.AttachTo("Locators", locator)); dataContextMock.Setup((ctxt) => ctxt.DeleteObject(locator)); dataContextMock.Setup((ctxt) => ctxt .SaveChangesAsync(locator)) .Returns(() => Task.Factory.StartNew<IMediaDataServiceResponse>(() => { if (--exceptionCount > 0) throw fakeException; return fakeResponse; })); // Cannot mock DataServiceQuery. Throw artificial exception to mark pass through saving changes. string artificialExceptionMessage = "artificialException"; dataContextMock.Setup((ctxt) => ctxt.CreateQuery<IAsset, AssetData>("Assets")).Throws(new Exception(artificialExceptionMessage)); _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object); locator.SetMediaContext(_mediaContext); try { locator.Delete(); } catch (Exception x) { Assert.AreEqual(artificialExceptionMessage, x.Message); } Assert.AreEqual(0, exceptionCount); }
public void TestLocatorCreateRetry() { var dataContextMock = new Mock<IMediaDataServiceContext>(); int exceptionCount = 2; var expected = new LocatorData { Name = "testData" }; var fakeResponse = new TestMediaDataServiceResponse { AsyncState = expected }; var fakeException = new WebException("testException", WebExceptionStatus.ConnectionClosed); dataContextMock.Setup((ctxt) => ctxt.AddObject("Files", It.IsAny<object>())); dataContextMock.Setup((ctxt) => ctxt .SaveChangesAsync(It.IsAny<object>())) .Returns(() => Task.Factory.StartNew<IMediaDataServiceResponse>(() => { if (--exceptionCount > 0) throw fakeException; return fakeResponse; })); _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object); var asset = new AssetData { Name = "testAssetData" }; asset.SetMediaContext(_mediaContext); ILocator locator = _mediaContext.Locators.CreateLocator(LocatorType.None, asset, new AccessPolicyData()); Assert.AreEqual(expected.Name, locator.Name); Assert.AreEqual(0, exceptionCount); }
public void InitilizeStubData() { string assetId = "nb:Id:" + Guid.NewGuid(); StorageAccountData storageAccountData = new StorageAccountData { IsDefault = true, Name = "test storage", }; _persistedChanges.Add(StorageAccountBaseCollection.EntitySet, new List <StorageAccountData> { storageAccountData }); AssetData assetData = new AssetData() { Id = assetId, AlternateId = String.Empty, Created = DateTime.UtcNow, LastModified = DateTime.UtcNow, Name = "Mock Asset", Options = (int)AssetCreationOptions.None, }; assetData.SetMediaContext(_mediaContextBase); _persistedChanges.Add(AssetCollection.AssetSet, new List <AssetData> { assetData }); string accessPolicyId = Guid.NewGuid().ToString(); AccessPolicyData accessPolicyData = new AccessPolicyData() { Id = accessPolicyId, Name = "Mock AccessPolicy", Created = DateTime.UtcNow.AddDays(-1), DurationInMinutes = 10000, LastModified = DateTime.UtcNow, Permissions = (int)AccessPermissions.Read }; accessPolicyData.SetMediaContext(_mediaContextBase); _persistedChanges.Add(AccessPolicyBaseCollection.AccessPolicySet, new List <AccessPolicyData> { accessPolicyData }); LocatorData locatorData = new LocatorData() { Id = Guid.NewGuid().ToString(), AssetId = assetId, Name = "Mock locator", AccessPolicyId = accessPolicyId, BaseUri = "http://" }; locatorData.SetMediaContext(_mediaContextBase); _persistedChanges.Add(LocatorBaseCollection.LocatorSet, new List <LocatorData> { locatorData }); _persistedChanges.Add(AssetFileCollection.FileSet, new List <AssetFileData> { new AssetFileData() { Id = Guid.NewGuid().ToString(), Created = DateTime.UtcNow, Name = "Mock File", ParentAssetId = assetId } }); _persistedChanges.Add(MediaProcessorBaseCollection.MediaProcessorSet, new List <MediaProcessorData> { new MediaProcessorData() { Id = Guid.NewGuid().ToString(), Name = "Mock Processor", Version = "1", Vendor = "mock" } }); _persistedChanges.Add(JobBaseCollection.JobSet, new List <JobData> { new JobData() { Id = Guid.NewGuid().ToString(), Name = "Mock Job", } }); }
/// <summary> /// Creates the data for the specified row. /// </summary> /// <param name="Row">The row.</param> internal Data Create(Row Row) { Data Data; switch (this.Index) { case 0: { Data = new BuildingData(Row, this); break; } case 1: { Data = new LocaleData(Row, this); break; } case 2: { Data = new ResourceData(Row, this); break; } case 3: { Data = new CharacterData(Row, this); break; } case 6: { Data = new BuildingClassData(Row, this); break; } case 7: { Data = new ObstacleData(Row, this); break; } case 8: { Data = new EffectData(Row, this); break; } case 9: { Data = new ParticleEmitterData(Row, this); break; } case 10: { Data = new ExperienceLevelData(Row, this); break; } case 11: { Data = new TrapData(Row, this); break; } case 12: { Data = new AllianceBadgeData(Row, this); break; } case 13: { Data = new GlobalData(Row, this); break; } case 14: { Data = new TownhallLevelData(Row, this); break; } case 15: { Data = new PrototypeData(Row, this); break; } case 16: { Data = new NpcData(Row, this); break; } case 17: { Data = new DecoData(Row, this); break; } case 18: { Data = new ResourcePackData(Row, this); break; } case 20: { Data = new MissionData(Row, this); break; } case 21: { Data = new BillingPackageData(Row, this); break; } case 22: { Data = new AchievementData(Row, this); break; } case 25: { Data = new SpellData(Row, this); break; } case 26: { Data = new HintData(Row, this); break; } case 27: { Data = new LandingShipData(Row, this); break; } case 28: { Data = new ArtifactData(Row, this); break; } case 29: { Data = new ArtifactBonusData(Row, this); break; } case 30: { Data = new DeepseaParameterData(Row, this); break; } case 31: { Data = new ExplorationCostData(Row, this); break; } case 34: { Data = new ResourceShipData(Row, this); break; } case 35: { Data = new LootBoxData(Row, this); break; } case 36: { Data = new LiberatedIncomeData(Row, this); break; } case 37: { Data = new RegionData(Row, this); break; } case 38: { Data = new DefenseRewardData(Row, this); break; } case 39: { Data = new LocatorData(Row, this); break; } case 40: { Data = new EventData(Row, this); break; } case 41: { Data = new FootstepData(Row, this); break; } case 42: { Data = new PersistentEventRewardData(Row, this); break; } case 43: { Data = new CommunityLinkData(Row, this); break; } case 44: { Data = new ShieldData(Row, this); break; } case 45: { Data = new AbTestData(Row, this); break; } case 46: { Data = new LetterData(Row, this); break; } case 47: { Data = new RankData(Row, this); break; } case 48: { Data = new CountryData(Row, this); break; } case 51: { Data = new BoomboxData(Row, this); break; } case 52: { Data = new HeroData(Row, this); break; } case 53: { Data = new HeroAbilityData(Row, this); break; } case 54: { Data = new OfferData(Row, this); break; } case 55: { Data = new DeepLinkData(Row, this); break; } case 56: { Data = new SectorData(Row, this); break; } case 57: { Data = new SectorBonusData(Row, this); break; } default: { Data = new Data(Row, this); break; } } return(Data); }