public void FunctionRepository_SaveCollection_ValidFunction_Expected_RepoUpdatedWithNewFunction() { IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository(); string functionName = "TestFunction"; List <string> arguments = new List <string>() { "args" }; List <string> argumentDescriptions = new List <string>() { "the first argument" }; string description = "Test Description"; string function2Name = "TestFunction2"; // The function repository must be loaded in order to populate the function list functionRepo.Load(); IFunction myfirstFunction = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, description); IFunction mySecondFunction = MathOpsFactory.CreateFunction(function2Name, arguments, argumentDescriptions, description); ICollection <IFunction> functionList = new List <IFunction>() { myfirstFunction, mySecondFunction }; functionRepo.Save(functionList); Assert.AreEqual(2, functionRepo.Find(c => c.FunctionName.Contains(functionName)).Count); }
public void FunctionRepository_Remove_ValidFunction_Expected_FunctionRemovedFromRepo() { IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository(); string functionName = "TestFunction"; List <string> arguments = new List <string>() { "args" }; List <string> argumentDescriptions = new List <string>() { "the first argument" }; string description = "Test Description"; // The function repository must be loaded in order to populate the function list functionRepo.Load(); IFunction myFunction = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, description); // save the new function functionRepo.Save(myFunction); functionRepo.Remove(myFunction); Assert.AreEqual(0, functionRepo.Find(c => c.FunctionName.Equals(functionName)).Count); }
public void FunctionRepository_SaveCollection_NullCollection_Expected_ArgumentNullException() { IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository(); // The function repository must be loaded in order to populate the function list functionRepo.Load(); int beforeEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count; functionRepo.Save((ICollection <IFunction>)null); Assert.IsNotNull(beforeEmptySave); }
public void FunctionRepository_SaveCollection_EmptyCollection_Expected_RepoFunctionCountRemainsTheSame() { IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository(); // The function repository must be loaded in order to populate the function list functionRepo.Load(); int beforeEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count; ICollection <IFunction> functionList = new List <IFunction>(); functionRepo.Save(functionList); int afterEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count; Assert.AreEqual(beforeEmptySave, afterEmptySave); }
public void FunctionRepository_Save_NullFunction_Expected_ArgumentNullException() { IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository(); // The function repository must be loaded in order to populate the function list functionRepo.Load(); try { functionRepo.Save((IFunction)null); } catch (ArgumentNullException) { // If there was a null argument exception, it's behaving Assert.IsTrue(true); } }
private void AddExistingWebResource() { if ((SelectedWebResource != null) && !string.IsNullOrEmpty(SelectedWebResource.Uri)) { dynamic fileData = FileNameProvider.GetFileName(); if (!fileData.HasError) { string localPath = fileData.LocalFilePath; string fileName = fileData.FileName; if (!string.IsNullOrEmpty(localPath)) { var newWebResource = new WebResourceViewModel(null); newWebResource.Name = fileName; newWebResource.Base64Data = Convert.ToBase64String(File.ReadAllBytes(localPath)); newWebResource.Uri = SelectedWebResource.Uri; newWebResource.SetParent(SelectedWebResource.Parent ?? SelectedWebResource); string fullName = string.Format("/{0}/{1}", newWebResource.Uri, newWebResource.Name); var existingWebResource = newWebResource.Parent.Children.FirstOrDefault(c => c.Name.Equals(fullName, StringComparison.InvariantCultureIgnoreCase)); if (existingWebResource != null) { UserMessageProvider.ShowUserErrorMessage(StringResources.Error_Website_Resource_Exists); return; } try { _webResources.Save(newWebResource); newWebResource.IsSelected = true; newWebResource.Parent.IsExpanded = true; SelectedWebResource = newWebResource; base.OnPropertyChanged("RootWebResource"); } catch (WebResourceUploadFailedException) { } } } } }
public void FunctionRepository_Save_ValidFunction_Expected_RepoUpdatedWithNewFunction() { IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository(); const string functionName = "TestFunction"; List <string> arguments = new List <string> { "args" }; List <string> argumentDescriptions = new List <string> { "the first argument" }; const string description = "Test Description"; // The function repository must be loaded in order to populate the function list functionRepo.Load(); IFunction myFunction = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, description); functionRepo.Save(myFunction); Assert.IsNotNull(functionRepo.Find(c => c.FunctionName.Equals(functionName))); }