示例#1
0
        public async Task TestExecuteOnItemReference()
        {
            var item = new DummyInt(5);

            var container = GetRandomContainerGrain <DummyInt>();
            var consumer  = new MultiStreamListConsumer <ContainerHostedElement <DummyInt> >(_provider);
            await consumer.SetInput(new List <StreamIdentity <ContainerHostedElement <DummyInt> > >() { await container.GetStreamIdentity() });

            var reference = (await container.AddRange(new List <DummyInt>()
            {
                item
            })).First();

            Assert.IsNotNull(reference);
            Assert.AreEqual(0, reference.Offset);
            Assert.AreEqual(container.GetPrimaryKey(), reference.ContainerId);

            await container.ExecuteSync(i => { i.Value += 2; }, reference);

            var tid = await container.EnumerateToStream();

            await consumer.TransactionComplete(tid);


            Assert.AreEqual(7, consumer.Items.First().Item.Value);
        }
        public void GetParams_OnValidCall_SetPeriod()
        {
            // Arrange
            var data = new StringBuilder();

            SetupShimsForHttpRequest();
            data.Append($"List\t{DummyString}");
            data.Append($"\nView\t{DummyString}");
            data.Append($"\nFilterField\t{DummyString}");
            data.Append($"\nFilterValue\t{DummyString}");
            data.Append($"\nGridName\t{DummyString}");
            _queryString.Add("period", DummyInt.ToString());
            _queryString.Add("data", Convert.ToBase64String(Encoding.ASCII.GetBytes(data.ToString())));
            ShimSPBaseCollection.AllInstances.GetEnumerator = instance =>
            {
                if (instance.GetType() == typeof(ShimSPFieldCollection) ||
                    instance.GetType() == typeof(SPFieldCollection))
                {
                    return(new List <SPField>
                    {
                        new ShimSPField()
                    }.GetEnumerator());
                }
                if (instance.GetType() == typeof(ShimSPViewFieldCollection) ||
                    instance.GetType() == typeof(SPViewFieldCollection))
                {
                    return(new List <string>
                    {
                        DummyString
                    }.GetEnumerator());
                }
                return(new List <SPForm>
                {
                    new ShimSPForm {
                        TypeGet = () => PAGETYPE.PAGE_DISPLAYFORM
                    },
                    new ShimSPForm {
                        TypeGet = () => PAGETYPE.PAGE_EDITFORM
                    },
                    new ShimSPForm {
                        TypeGet = () => PAGETYPE.PAGE_NEWFORM
                    }
                }.GetEnumerator());
            };

            // Act
            TestEntity.getParams(new ShimSPWeb());

            // Assert
            Get <int>("period").ShouldBe(DummyInt);
        }
        public void EventReceiverManager_StringDataAndSPWebIsNotNull_ReturnException()
        {
            // Arrange
            var parameters = new object[] { DummyString, new ShimSPWeb().Instance };

            ShimXDocument.ParseString            = _ => new ShimXDocument();
            ShimXDocument.AllInstances.RootGet   = _ => new ShimXElement();
            ShimXContainer.AllInstances.Elements = _ => new List <XElement>()
            {
                new ShimXElement()
            };
            ShimXElement.AllInstances.AttributeXName  = (_, _1) => new ShimXAttribute();
            ShimXElement.AllInstances.ValueGet        = _ => new Guid().ToString();
            ShimTimer.CancelTimerJobSPWebGuid         = (_, _1) => { };
            ShimXContainer.AllInstances.ElementsXName = (_, _1) => new List <XElement>()
            {
                new ShimXElement()
            };
            ShimXContainer.AllInstances.ElementXName = (_, _1) => new ShimXElement();
            var count = 0;

            ShimXAttribute.AllInstances.ValueGet = _ =>
            {
                count++;
                if (count == 5)
                {
                    return(DummyInt.ToString());
                }
                else if (count == 6)
                {
                    return("list");
                }
                else
                {
                    return(new Guid().ToString());
                }
            };
            ShimSPSite.AllInstances.OpenWebGuid = (_, _1) => new ShimSPWeb();
            ShimSPWeb.AllInstances.ListsGet     = _ => new ShimSPListCollection();
            ShimSPListCollection.AllInstances.GetListByIdGuidBoolean = (_, _1, _2) => new ShimSPList();
            ShimSPWeb.AllInstances.Dispose = _ => { };

            // Act
            var actualResult = _privateType.InvokeStatic(
                EventReceiverManager,
                parameters);

            // Assert
            actualResult.ShouldNotBeNull();
            actualResult.ShouldBe("<Result Status=\"1\"><Error ID=\"900100\">Error: Object reference not set to an instance of an object.</Error></Result>");
        }
        public void Btn_Click_OnValidCall_AddToCookies()
        {
            // Arrange
            SetupShimsForHttpRequest();
            ShimListControl.AllInstances.SelectedValueGet = _ => DummyInt.ToString();

            // Act
            PrivateObject.Invoke("btn_Click", new object(), new ImageClickEventArgs(DummyInt, DummyInt));

            // Assert
            this.ShouldSatisfyAllConditions(
                () => _cookies["EPMLiveTSPeriod"].ShouldNotBeNull(),
                () => _cookies["EPMLiveTSPeriod"]["period"].ShouldNotBeNull(),
                () => _cookies["EPMLiveTSPeriod"]["period"].ShouldContain("2"));
        }
示例#5
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        speed = 1.5f;
        if (ApplicationModel.gameType == 0)
        {
            speed = 2f;
        }
        rb2d = GetComponent <Rigidbody2D> ();
    }
        private void TestRenderWebPart(string newPeriod, int activation = 0, bool disabled = false, int arrPeriodsCount = 1)
        {
            // Arrange
            var stringWriter = new StringWriter();

            SetupShimsForSqlClient();
            SetupShimsForSharePoint();
            SetupShimsForHttpRequest();
            PrivateObject.SetFieldOrProperty("Activation", activation);
            PrivateObject.SetFieldOrProperty(Disabled, disabled);
            PrivateObject.SetFieldOrProperty("Error", DummyString);
            PrivateObject.SetFieldOrProperty("Act", new Act(new ShimSPWeb()));
            var sortedList = new SortedList();

            if (arrPeriodsCount > 0)
            {
                sortedList.Add(DummyInt, DummyInt);
            }
            PrivateObject.SetFieldOrProperty(Periods, sortedList);
            _queryString.Add("NewPeriod", newPeriod);
            ShimApprovalsBase.AllInstances.RenderGridHtmlTextWriterSPWebStringStringStringStringStringStringBoolean =
                (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) => { };
            SystemWebPartsFakes.AllInstances.WebPartManagerGet    = _ => new ShimSPWebPartManager();
            ShimWebPart.AllInstances.WebPartManagerGet            = _ => new ShimSPWebPartManager();
            SystemWebPartManagerFakes.AllInstances.WebPartsGet    = _ => new SystemWebPartCollection();
            ShimReadOnlyCollectionBase.AllInstances.GetEnumerator = _ => new List <SystemWebPart>
            {
                new ListViewWebPart()
            }.GetEnumerator();

            // Act
            using (var htmlTextWriter = new HtmlTextWriter(stringWriter))
            {
                PrivateObject.Invoke("RenderWebPart", htmlTextWriter);
            }
            var actualResult = stringWriter.ToString();

            // Assert
            if (activation != 0)
            {
                actualResult.ShouldContain("You have not purchased this feature");
            }
            else if (disabled)
            {
                actualResult.ShouldContain("Timesheet approvals are disabled.");
            }
            else if (arrPeriodsCount.Equals(0))
            {
                actualResult.ShouldContain("No Periods Defined.");
            }
            else
            {
                actualResult.ShouldSatisfyAllConditions(
                    () => actualResult.ShouldContain(DummyString),
                    () =>
                {
                    if (!string.IsNullOrEmpty(newPeriod))
                    {
                        _cookies["EPMLiveTSPeriod"].ShouldNotBeNull();
                        _cookies["EPMLiveTSPeriod"]["period"].ShouldNotBeNull();
                        _cookies["EPMLiveTSPeriod"]["period"].ShouldContain(DummyInt.ToString());
                    }
                });
            }
        }
        private void TestRenderWebPart(int gridType, string isDefault, int previousPeriod, int nextPeriod, int activation = 0, bool bHasPeriods = true)
        {
            // Arrange
            var stringWriter = new StringWriter();
            var viewManager  = new ViewManager(DummyString);

            viewManager.Views = new Dictionary <string, Dictionary <string, string> >
            {
                { DummyString, new Dictionary <string, string> {
                      { "Default", isDefault }
                  } }
            };
            SetupShimsForSqlClient();
            SetupShimsForSharePoint();
            SetupShimsForHttpRequest();
            PrivateObject.SetField("tb", new TimeDebug(DummyString, bool.TrueString));
            PrivateObject.SetField("activation", activation);
            PrivateObject.SetField("bHasPeriods", bHasPeriods);
            PrivateObject.SetField("bTsLocked", true);
            _queryString.Add("Delegate", DummyInt.ToString());
            _queryString.Add(DummyString, DummyString);
            PrivateObject.SetField("sFullGridId", DummyString);
            PrivateObject.SetField("sPeriodName", DummyString);
            PrivateObject.SetField("sDataParam", DummyString);
            PrivateObject.SetField("sPeriodList", $"{DummyString}|{DummyString},{DummyString}|{DummyString}{DummyString}");
            PrivateObject.SetField("GridType", gridType);
            PrivateObject.SetField("iPreviousPeriod", previousPeriod);
            PrivateObject.SetField("iNextPeriod", nextPeriod);
            PrivateObject.SetField("act", new Act(new ShimSPWeb()));
            ShimWebPart.AllInstances.QualifierGet = _ => DummyString;
            SystemWebPartsFakes.AllInstances.WebPartManagerGet    = _ => new ShimSPWebPartManager();
            ShimWebPart.AllInstances.WebPartManagerGet            = _ => new ShimSPWebPartManager();
            SystemWebPartManagerFakes.AllInstances.WebPartsGet    = _ => new SystemWebPartCollection();
            ShimReadOnlyCollectionBase.AllInstances.GetEnumerator = _ => new List <SystemWebPart>
            {
                new ListViewWebPart()
            }.GetEnumerator();
            ShimSPWeb.AllInstances.UrlGet                 = _ => "/";
            ShimHttpRequest.AllInstances.RawUrlGet        = _ => $"{DummyUrl}?test=test";
            ShimCoreFunctions.getConfigSettingSPWebString = (_, name) =>
            {
                if (name.Equals("EPMLiveTSAllowNotes"))
                {
                    return(bool.TrueString);
                }
                if (name.Equals("EPMLiveDaySettings"))
                {
                    return(string.Join("|", Enumerable.Repeat <string>(bool.TrueString, 30)));
                }
                return(DummyString);
            };
            PrivateObject.SetField("views", viewManager);
            PrivateObject.SetField("settings", new TimesheetSettings(new ShimSPWeb()));

            // Act
            using (var htmlTextWriter = new HtmlTextWriter(stringWriter))
            {
                PrivateObject.Invoke("RenderWebPart", htmlTextWriter);
            }
            var actualResult = stringWriter.ToString();

            // Assert
            if (activation != 0)
            {
                actualResult.ShouldContain("Too many users activated for this feature.");
            }
            else if (!bHasPeriods)
            {
                actualResult.ShouldContain("There are no periods setup for this TimeSheet. Please contact your system administrator");
            }
            else
            {
                actualResult.ShouldSatisfyAllConditions(
                    () => actualResult.ShouldContain("CanEditViews = true"),
                    () => actualResult.ShouldContain($"var TSObject{DummyString} = new Object()"),
                    () => actualResult.ShouldContain($"<option value={DummyString}>"),
                    () => actualResult.ShouldContain($"disabled='disabled'"),
                    () => actualResult.ShouldContain(@"var viewNameDiv = document.getElementById(""viewNameDiv"");"));
            }
        }
 public void RenderWebPart_OnDisabled_WriteToHtmlTextWriter()
 {
     // Arrange, Act, Assert
     TestRenderWebPart(DummyInt.ToString(), 0, true);
 }
 public void RenderWebPart_OneriodsCountIsZero_WriteToHtmlTextWriter()
 {
     // Arrange, Act, Assert
     TestRenderWebPart(DummyInt.ToString(), 0, false, 0);
 }
 public void RenderWebPart_OnValidCall_WriteToHtmlTextWriter()
 {
     // Arrange, Act, Assert
     TestRenderWebPart(DummyInt.ToString());
 }
 public void RenderWebPart_OnActivationsNotZero_WriteToHtmlTextWriter()
 {
     // Arrange, Act, Assert
     TestRenderWebPart(DummyInt.ToString(), 5);
 }
 public void CreateChildControls_OnValidCallAndDtPeriodsHasRows_UpdateControls()
 {
     // Arrange, Act, Assert
     TestCreateChildControls(DummyInt.ToString(), true, 0, true);
 }
 public void CreateChildControls_OnValidCall_UpdateControls()
 {
     // Arrange, Act, Assert
     TestCreateChildControls(DummyInt.ToString(), false, DummyInt, false);
 }
        private void TestCreateChildControls(string periodId, bool dtPeriodsHasRows, int gridType, bool scriptManagerIsNull)
        {
            // Arrange
            SetupShimsForSharePoint();
            SetupShimsForSqlClient();
            SetupShimsForHttpRequest();
            PrivateObject.SetField("tb", new TimeDebug(DummyString, bool.TrueString));
            PrivateObject.SetField("GridType", gridType);
            ShimSPPersistedObject.AllInstances.PropertiesGet = _ => new Hashtable
            {
                { "EPMLiveKeys", $"{DummyString}\t{DummyString}" }
            };
            ShimAct.AllInstances.CheckOnlineFeatureLicenseActFeatureStringSPSite = (_, _2, _3, _4) => 0;
            if (!string.IsNullOrEmpty(periodId))
            {
                _queryString.Add("NewPeriod", periodId);
            }
            _httpRequest.QueryString.Add("Delegate", DummyInt.ToString());
            ShimCoreFunctions.getConnectionStringGuid  = _ => DummyString;
            ShimDbDataAdapter.AllInstances.FillDataSet = (_, ds) =>
            {
                var dataTable = new DataTable();
                dataTable.Columns.Add("CurPeriod", typeof(string));
                dataTable.Columns.Add("period_id", typeof(int));
                dataTable.Columns.Add("period_start", typeof(DateTime));
                dataTable.Columns.Add("period_end", typeof(DateTime));
                dataTable.Rows.Add("2", 2, DateTime.Now, DateTime.Now);
                if (dtPeriodsHasRows)
                {
                    dataTable.Rows.Add("1", DummyInt, DateTime.Now, DateTime.Now);
                }
                ds.Tables.Add(dataTable);
                return(DummyInt);
            };
            ShimSqlDataReader.AllInstances.GetDateTimeInt32 = (_, indx) =>
            {
                if (indx == 0)
                {
                    return(DateTime.Now.AddDays(-2));
                }
                return(DateTime.Now);
            };
            ShimCoreFunctions.getConfigSettingSPWebString = (_, name) =>
            {
                if (name.Equals("EPMLiveTSAllowNotes"))
                {
                    return(bool.TrueString);
                }
                if (name.Equals("EPMLiveDaySettings"))
                {
                    return(string.Join("|", Enumerable.Repeat <string>(bool.TrueString, 30)));
                }
                return(DummyString);
            };
            ShimAPITeam.GetResourcePoolStringSPWebXmlNodeListBoolean = (_, _2, _3, _4) =>
            {
                var dataTable = new DataTable();
                dataTable.Columns.Add("SPID", typeof(string));
                dataTable.Columns.Add("Title", typeof(string));
                dataTable.Rows.Add(DummyInt.ToString(), DummyString);
                return(dataTable);
            };
            ShimScriptManager.GetCurrentPage       = _ => scriptManagerIsNull ? null : new ScriptManager();
            ShimServiceReference.ConstructorString = (_, __) => { };
            ShimHttpUtility.HtmlEncodeString       = str => str;
            ShimPage.AllInstances.FormGet          = _ => new HtmlForm();

            // Act
            PrivateObject.Invoke("CreateChildControls");

            // Assert
            this.ShouldSatisfyAllConditions(
                () => Get <string>("sDelegates").ShouldContain(DummyString),
                () => Get <ViewManager>("views").ShouldNotBeNull(),
                () => Get <string>("sDataParam").ShouldContain("UserId=\"1\"/>"),
                () => Get <string>("TSCols").ShouldContain(bool.TrueString),
                () => Get <string>("TSDCols").ShouldContain(bool.TrueString),
                () => Get <string>("sLayoutParam").ShouldContain("UserId=\"1\""));
        }
示例#15
0
 public void RenderWebPart_OnReadBooleanIsFalseAndReadIntIsTwo_WriteToHtmlTextWriter()
 {
     // Arrange, Act, Assert
     TestRenderWebPart(DummyInt.ToString(), DummyInt.ToString(), 2, false);
 }
示例#16
0
 public void RenderWebPart_OnReadIntIsThree_WriteToHtmlTextWriter()
 {
     // Arrange, Act, Assert
     TestRenderWebPart(DummyInt.ToString(), DummyInt.ToString(), 3);
 }
示例#17
0
 public void RenderWebPart_OnPeriodIsEmpty_WriteToHtmlTextWriter()
 {
     // Arrange, Act, Assert
     TestRenderWebPart(string.Empty, DummyInt.ToString(), 2);
 }
示例#18
0
 public void RenderWebPart_OnEditIsZero_WriteToHtmlTextWriter()
 {
     // Arrange, Act, Assert
     TestRenderWebPart(DummyInt.ToString(), "0");
 }