test/Misc/EFTools/InProcTests/UndoRedoTestsRemote.cs
/// <summary>
///     Simple FunctionImport tests:
///     1. Create 3 function imports, change return type, sproc, undo 5 times, redo 5 times
/// </summary>
Simple FunctionImport tests:
1. Create 3 function imports, change return type, sproc, undo 5 times, redo 5 times
Simple FunctionImport tests : 1 . Create 3 function imports change return type sproc undo 5 times redo 5 times
[TestMethod]
        [HostType("VS IDE")]
        public void Simple_FunctionImport()
        {
            UITestRunner.Execute(TestContext.TestName, 
                () =>
                    {
                        const string typePrefix = "Simple_FunctionImport";
                        const string testName = "UndoRedo." + typePrefix;
                        ExecuteUndoRedoTest(
                            testName, "NorthwindModel.edmx", (commandProcessorContext, artifact) =>
                                {
                                    var dte = VsIdeTestHostContext.Dte;
                                    var conceptualEntityContainer =
                                        (ConceptualEntityContainer)artifact.ConceptualModel().EntityContainers().Single();
                                    var entityContainerMapping = artifact.MappingModel().EntityContainerMappings().Single();
                                    Action<Function, string, object> createFunctionImport = (function, functionImportName, returnType) =>
                                        {
                                            var functionImportCmd = new CreateFunctionImportCommand(
                                                conceptualEntityContainer, function, functionImportName, returnType);
                                            var functionImportMappingCmd = new CreateFunctionImportMappingCommand(
                                                entityContainerMapping, function, functionImportCmd.Id);
                                            functionImportMappingCmd.AddPreReqCommand(functionImportCmd);
                                            new CommandProcessor(commandProcessorContext, functionImportCmd, functionImportMappingCmd)
                                                .Invoke();
                                        };
                                    var function1 = artifact.GetFreshStorageFunction("GetFreightCost");
                                    createFunctionImport(function1, "a", Resources.NoneDisplayValueUsedForUX);
                                    Assert.AreEqual(
                                        "NorthwindModel.Store.GetFreightCost", artifact.GetFreshFunctionMapping("a").FunctionName.RefName);
                                    Assert.AreEqual(
                                        Resources.NoneDisplayValueUsedForUX,
                                        ((DefaultableValue<string>)artifact.GetFreshFunctionImport("a").ReturnType).Value);
                                    createFunctionImport(function1, "aa", "Int16");
                                    Assert.AreEqual(
                                        "NorthwindModel.Store.GetFreightCost", artifact.GetFreshFunctionMapping("aa").FunctionName.RefName);
                                    Assert.AreEqual(
                                        "Collection(Int16)",
                                        ((DefaultableValue<string>)artifact.GetFreshFunctionImport("aa").ReturnType).Value);
                                    var function2 = artifact.GetFreshStorageFunction("Sales_by_Year");
                                    createFunctionImport(function2, "aaa", artifact.GetFreshConceptualEntity("Orders"));
                                    Assert.AreEqual(
                                        "NorthwindModel.Store.Sales_by_Year", artifact.GetFreshFunctionMapping("aaa").FunctionName.RefName);
                                    Assert.AreEqual(
                                        "Collection(NorthwindModel.Orders)",
                                        ((SingleItemBinding<EntityType>)artifact.GetFreshFunctionImport("aaa").ReturnType).RefName);
                                    var functionImport = artifact.GetFreshFunctionImport("aaa");
                                    new CommandProcessor(
                                        commandProcessorContext,
                                        new ChangeFunctionImportCommand(
                                            conceptualEntityContainer,
                                            functionImport,
                                            function2,
                                            "aaa",
                                            functionImport.IsComposable.Value,
                                             true,
                                            Resources.NoneDisplayValueUsedForUX)
                                        ).Invoke();
                                    Assert.AreEqual(
                                        "NorthwindModel.Store.Sales_by_Year", artifact.GetFreshFunctionMapping("aaa").FunctionName.RefName,
                                        "Mapping must not be changed.");
                                    Assert.AreEqual(
                                        Resources.NoneDisplayValueUsedForUX,
                                        ((DefaultableValue<string>)artifact.GetFreshFunctionImport("aaa").ReturnType).Value);
                                    functionImport = artifact.GetFreshFunctionImport("aaa");
                                    new CommandProcessor(
                                        commandProcessorContext,
                                        new ChangeFunctionImportCommand(
                                            conceptualEntityContainer,
                                            functionImport,
                                            null,
                                            "aaa",
                                            functionImport.IsComposable.Value,
                                            false,
                                            null)).Invoke();
                                    Assert.IsNotNull(artifact.GetFreshFunctionImport("aaa"));
                                    Assert.AreEqual(
                                        Resources.NoneDisplayValueUsedForUX,
                                        ((DefaultableValue<string>)artifact.GetFreshFunctionImport("aaa").ReturnType).Value);
                                    Assert.IsNull(artifact.GetFreshFunctionMapping("aaa"), "Mapping should have been deleted.");
                                    Assert.IsNotNull(
                                        artifact.GetFreshStorageFunction("Sales_by_Year"), "Function should not have been deleted.");
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), UndoCommand);
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), UndoCommand);
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), UndoCommand);
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), UndoCommand);
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), UndoCommand);
                                    Assert.IsFalse(conceptualEntityContainer.FunctionImports().Any());
                                    Assert.IsFalse(entityContainerMapping.FunctionImportMappings().Any());
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), RedoCommand);
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), RedoCommand);
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), RedoCommand);
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), RedoCommand);
                                    dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), RedoCommand);
                                    Assert.AreEqual(3, conceptualEntityContainer.FunctionImports().Count());
                                    Assert.AreEqual(2, entityContainerMapping.FunctionImportMappings().Count());
                                    Assert.AreEqual(
                                        "NorthwindModel.Store.GetFreightCost", artifact.GetFreshFunctionMapping("a").FunctionName.RefName);
                                    Assert.AreEqual(
                                        "NorthwindModel.Store.GetFreightCost", artifact.GetFreshFunctionMapping("aa").FunctionName.RefName);
                                });
                    });
        }
[ TestMethod ] [ HostType ( " " ) ] public void Simple_FunctionImport ( ) { UITestRunner . Execute ( TestContext . TestName , ( ) => { const string typePrefix = " " ; const string testName = " " + typePrefix ; ExecuteUndoRedoTest ( testName , " " , ( commandProcessorContext , artifact ) => { var dte = VsIdeTestHostContext . Dte ; var conceptualEntityContainer = ( ConceptualEntityContainer ) artifact . ConceptualModel ( ) . EntityContainers ( ) . Single ( ) ; var entityContainerMapping = artifact . MappingModel ( ) . EntityContainerMappings ( ) . Single ( ) ; Action < Function , string , object > createFunctionImport = ( function , functionImportName , returnType ) => { var functionImportCmd = new CreateFunctionImportCommand ( conceptualEntityContainer , function , functionImportName , returnType ) ; var functionImportMappingCmd = new CreateFunctionImportMappingCommand ( entityContainerMapping , function , functionImportCmd . Id ) ; functionImportMappingCmd . AddPreReqCommand ( functionImportCmd ) ; new CommandProcessor ( commandProcessorContext , functionImportCmd , functionImportMappingCmd ) . Invoke ( ) ; } ; var function1 = artifact . GetFreshStorageFunction ( " " ) ; createFunctionImport ( function1 , " " , Resources . NoneDisplayValueUsedForUX ) ; Assert . AreEqual ( " " , artifact . GetFreshFunctionMapping ( " " ) . FunctionName . RefName ) ; Assert . AreEqual ( Resources . NoneDisplayValueUsedForUX , ( ( DefaultableValue < string > ) artifact . GetFreshFunctionImport ( " " ) . ReturnType ) . Value ) ; createFunctionImport ( function1 , " " , " " ) ; Assert . AreEqual ( " " , artifact . GetFreshFunctionMapping ( " " ) . FunctionName . RefName ) ; Assert . AreEqual ( " " , ( ( DefaultableValue < string > ) artifact . GetFreshFunctionImport ( " " ) . ReturnType ) . Value ) ; var function2 = artifact . GetFreshStorageFunction ( " " ) ; createFunctionImport ( function2 , " " , artifact . GetFreshConceptualEntity ( " " ) ) ; Assert . AreEqual ( " " , artifact . GetFreshFunctionMapping ( " " ) . FunctionName . RefName ) ; Assert . AreEqual ( " " , ( ( SingleItemBinding < EntityType > ) artifact . GetFreshFunctionImport ( " " ) . ReturnType ) . RefName ) ; var functionImport = artifact . GetFreshFunctionImport ( " " ) ; new CommandProcessor ( commandProcessorContext , new ChangeFunctionImportCommand ( conceptualEntityContainer , functionImport , function2 , " " , functionImport . IsComposable . Value , true , Resources . NoneDisplayValueUsedForUX ) ) . Invoke ( ) ; Assert . AreEqual ( " " , artifact . GetFreshFunctionMapping ( " " ) . FunctionName . RefName , " " ) ; Assert . AreEqual ( Resources . NoneDisplayValueUsedForUX , ( ( DefaultableValue < string > ) artifact . GetFreshFunctionImport ( " " ) . ReturnType ) . Value ) ; functionImport = artifact . GetFreshFunctionImport ( " " ) ; new CommandProcessor ( commandProcessorContext , new ChangeFunctionImportCommand ( conceptualEntityContainer , functionImport , null , " " , functionImport . IsComposable . Value , false , null ) ) . Invoke ( ) ; Assert . IsNotNull ( artifact . GetFreshFunctionImport ( " " ) ) ; Assert . AreEqual ( Resources . NoneDisplayValueUsedForUX , ( ( DefaultableValue < string > ) artifact . GetFreshFunctionImport ( " " ) . ReturnType ) . Value ) ; Assert . IsNull ( artifact . GetFreshFunctionMapping ( " " ) , " " ) ; Assert . IsNotNull ( artifact . GetFreshStorageFunction ( " " ) , " " ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , UndoCommand ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , UndoCommand ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , UndoCommand ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , UndoCommand ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , UndoCommand ) ; Assert . IsFalse ( conceptualEntityContainer . FunctionImports ( ) . Any ( ) ) ; Assert . IsFalse ( entityContainerMapping . FunctionImportMappings ( ) . Any ( ) ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , RedoCommand ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , RedoCommand ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , RedoCommand ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , RedoCommand ) ; dte . ExecuteCommandForOpenDocument ( artifact . LocalPath ( ) , RedoCommand ) ; Assert . AreEqual ( 3 , conceptualEntityContainer . FunctionImports ( ) . Count ( ) ) ; Assert . AreEqual ( 2 , entityContainerMapping . FunctionImportMappings ( ) . Count ( ) ) ; Assert . AreEqual ( " " , artifact . GetFreshFunctionMapping ( " " ) . FunctionName . RefName ) ; Assert . AreEqual ( " " , artifact . GetFreshFunctionMapping ( " " ) . FunctionName . RefName ) ; } ) ; } ) ; }
Simple FunctionImport tests:
1.
Simple FunctionImport tests : 1 .
// CREATE THREE FUNCTION IMPORTS (don't undo/redo yet) // CHANGE RETURN TYPE (don't undo/redo yet) /* changeReturnType */ // CHANGE STORED PROCEDURE NAME (don't undo/redo yet) // UNDO/REDO 5 LEVELS  // undo five times (Undo Change Sproc, Change Return Type, Create FI3, Create FI2, Create FI1) // redo five times (Redo Create FI1, FI2, FI3, Change Return Type, Change Sproc)