Ejemplo n.º 1
0
 public void ReplaceNulls()
 {
     PrivateType internalAssertEx = new PrivateType(typeof(AssertEx));
     object oNull = null;
     Assert.AreEqual("(null)", internalAssertEx.InvokeStatic("ReplaceNulls", oNull), "AssertEx.ReplaceNulls didn't return the correct value.");
     Assert.AreEqual("teststring", internalAssertEx.InvokeStatic("ReplaceNulls", "teststring"), "AssertEx.ReplaceNulls didn't return the correct value.");
     Assert.AreEqual("test\\0string", internalAssertEx.InvokeStatic("ReplaceNulls", "test\0string"), "AssertEx.ReplaceNulls didn't return the correct value.");
 }
        public void KeyGenerationTest()
        {
            PrivateType pt = new PrivateType(typeof(AsymmetricBlobCryptoProvider));

            byte[] key = (byte[])pt.InvokeStatic("GenerateRandomKey");
            byte[] encryptedKey;
            byte[] decryptedKey;

            var rsa = new RSACryptoServiceProvider();
            rsa.ImportCspBlob(testCspBlob);

            using (ICspProxy cspProxy = new DisposingCspProxy(rsa, rsa.KeySize))
            {
                encryptedKey = cspProxy.Encrypt(key);
                decryptedKey = cspProxy.Decrypt(encryptedKey);
            }

            // The two keys shouldn't be the same...
            Assert.IsFalse(key.SequenceEqual(encryptedKey));

            // And we expect it to grow to the same size as the RSA Key
            Assert.IsTrue(encryptedKey.Length == 4096 / 8);

            // Sanity check, it should be 256 bit / 32 bytes and not contain any zeros.
            Assert.IsTrue(decryptedKey.Length == 256/8, "Key length is incorrect");
            Assert.IsTrue(decryptedKey[0] != 0, "Key starts with an empty byte");

            // And of course, the round tripped key should match original
            Assert.IsTrue(key.SequenceEqual(decryptedKey));
        }
 public void TestIfCorrectNumbersOfMinesAreCreated()
 {
     PrivateType privateType = new PrivateType(typeof(GameBoardGenerator));
     var fieldSize = 1;
     int startRandomRange = ((15 * fieldSize * fieldSize) / 100) + 1;
     int endRandomRange = ((30 * fieldSize * fieldSize) / 100) + 1;
     int randomCheck = (int)privateType.InvokeStatic("RandomGenerator", startRandomRange, endRandomRange);
     Assert.IsTrue(randomCheck >= 1);
 }
Ejemplo n.º 4
0
        public void TestGetDestFilePath_NoExtensions()
        {
            const string expected = @"C:\Garmin\Activities\1990-01-01-00-00-00_duplicated";
            const string srcPath = @"C:\Garmin\Activities\1990-01-01-00-00-00";

            var pt = new PrivateType(typeof(Program));
            var actual = (string)pt.InvokeStatic("GetDestFilePath", new object[] { srcPath });

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public void TestKernel()
        {
            var kernel = (IKernel)inboxWatcherPrivateObject.Invoke("ConfigureNinject");

            var pvtType = new PrivateType(typeof(InboxWatcher.InboxWatcher));
            var configs = (List <ImapMailBoxConfiguration> ) pvtType.InvokeStatic("GetConfigs");

            var client = kernel.Get<IImapFactory>(new ConstructorArgument("configuration", configs[0]));
            var imapMailBox = kernel.Get<IImapMailBox>(new ConstructorArgument("config", configs[0]));
            Debugger.Break();
        }
Ejemplo n.º 6
0
        public void V2MasterPasswordIsUniqueTest()
        {
            string key1 = CalculateNewMasterPasswordKey(MASTERPASSWORD);
            string key2 = CalculateNewMasterPasswordKey(MASTERPASSWORD);
            Assert.AreNotEqual(key1, key2, "generated master password key always equals.");

            var accessor = new PrivateType(typeof(PasswordFunctions2));
            byte[] keySalt = (byte[])accessor.InvokeStatic("CreateRandomKeySalt", new Object[] {});
            key1 = CalculateV2Key(accessor, keySalt);
            key2 = CalculateV2Key(accessor, keySalt);
            Assert.AreEqual(key1, key2, "generated master password doesn't equal.");
        }
Ejemplo n.º 7
0
        public void GetNextLine_X12LineAsDelimiter_CorrectDataReturned()
        {
            //arrange
            const int srcNo = 3;
            var       LineFeederCreatePT = new PrivateType(typeof(LineFeederCreator));
            var       feeder             = (LineFeederForSource)LineFeederCreatePT.InvokeStatic("CreateLineFeeder", new object[] { new StreamReader(_x12StreamLineAsDelimiter, Encoding.UTF8), srcNo, KindOfTextData.X12, false, false, "*", null }); //segment delimiter can be anything, but null here
            var       tuplesFed          = new List <Tuple <ExternalLine, int> >();

            //act
            var tupleFed = feeder.GetNextLine();

            while (tupleFed != null)
            {
                tuplesFed.Add(tupleFed);
                tupleFed = feeder.GetNextLine();
            }

            //assert
            feeder.Should().BeOfType <X12FeederForSource>();
            //note that segment delimiters are stripped out of segments
            tuplesFed.Count.Should().Be(37);
            tuplesFed[0].Item1.Text.Should().Be("ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>\r");
            tuplesFed[0].Item2.Should().Be(3);
            tuplesFed[1].Item1.Text.Should().Be("GS*PO*4405197800*999999999*20101127*1719*1421*X*004010VICS");
            tuplesFed[1].Item2.Should().Be(3);
            tuplesFed[2].Item1.Text.Should().Be("ST*850*000000010");
            tuplesFed[2].Item2.Should().Be(3);
            tuplesFed[4].Item1.Text.Should().Be("REF*DP*038");
            tuplesFed[4].Item2.Should().Be(3);
            tuplesFed[7].Item1.Text.Should().Be("DTM*002*20101214");
            tuplesFed[7].Item2.Should().Be(3);
            tuplesFed[9].Item1.Text.Should().Be("PKG*F*66***REGULAR");
            tuplesFed[9].Item2.Should().Be(3);
            tuplesFed[12].Item1.Text.Should().Be("N3*31875 SOLON RD");
            tuplesFed[12].Item2.Should().Be(3);
            tuplesFed[17].Item1.Text.Should().Be("PO1*2*220*EA*13.79*TE*CB*066850-116*PR*RO*VN*RD5322");
            tuplesFed[17].Item2.Should().Be(3);
            tuplesFed[20].Item1.Text.Should().Be("PO1*3*126*EA*10.99*TE*CB*060733-110*PR*RO*VN*XY5266");
            tuplesFed[20].Item2.Should().Be(3);
            tuplesFed[21].Item1.Text.Should().Be("PID*F****LARGE WIDGET");
            tuplesFed[21].Item2.Should().Be(3);
            tuplesFed[26].Item1.Text.Should().Be("PO1*5*72*EA*7.5*TE*CB*065374-118*PR*RO*VN*RV0524");
            tuplesFed[26].Item2.Should().Be(3);
            tuplesFed[28].Item1.Text.Should().Be("PO4*4*4*EA");
            tuplesFed[28].Item2.Should().Be(3);
            tuplesFed[32].Item1.Text.Should().Be("CTT*6");
            tuplesFed[32].Item2.Should().Be(3);
            tuplesFed[36].Item1.Text.Should().Be("IEA*1*000003438");
            tuplesFed[36].Item2.Should().Be(3);
        }
Ejemplo n.º 8
0
        public void GetMatchingDatabaseFieldAttribute_ShouldThrowException_WhenGivenPropertyWithoutAttribute()
        {
            try
            {
                PropertyInfo[] simpleProperty = (typeof(SimpleClass)).GetProperties();

                PrivateType pt = new PrivateType(typeof(MatchingDatabaseFieldHelper));
                pt.InvokeStatic("GetMatchingDatabaseFieldAttribute", simpleProperty[0]);
            }
            catch (TargetInvocationException ex)
            {
                throw ex.InnerException;
            }
        }
        public void GetName_StaticMethodTest()
        {
            //arrange
            string name = "Abhishek";
            int age = 30;
            Salary osalary = new Salary(name, age);

            //act
            PrivateType pType = new PrivateType(typeof(Salary));
            string returnValue = pType.InvokeStatic("GetName", osalary) as string;

            //assert
            Assert.AreEqual(name, returnValue);
        }
        public void TestGeoJsonToEsriGeometryPolygon()
        {
            var polyJson = TestResources.NorthCarolinaPolygonGeoJson;


            PrivateType pt = new PrivateType(typeof(GeometryClasses));

            var poly = (IPolygon)pt.InvokeStatic("GeoJsonToEsriPolygon", polyJson);

            if (poly != null)
            {
                Assert.IsTrue(true);
            }
        }
Ejemplo n.º 11
0
        public void TestTraffic()
        {
            // Test pilot traffic data
            string  jsonString = System.IO.File.ReadAllText("edsmTraffic.json");
            JObject response   = JsonConvert.DeserializeObject <JObject>(jsonString);

            PrivateType starMapService          = new PrivateType(typeof(StarMapService));
            Dictionary <string, object> traffic = (Dictionary <string, object>)starMapService.InvokeStatic("ParseStarMapTraffic", new object[] { response });

            Assert.IsNotNull(traffic);
            Assert.AreEqual(9631, (long?)traffic["total"]);
            Assert.AreEqual(892, (long?)traffic["week"]);
            Assert.AreEqual(193, (long?)traffic["day"]);
        }
Ejemplo n.º 12
0
        public void TestDeaths()
        {
            // Test pilot mortality data
            string  jsonString = System.IO.File.ReadAllText("edsmDeaths.json");
            JObject response   = JsonConvert.DeserializeObject <JObject>(jsonString);

            PrivateType starMapService         = new PrivateType(typeof(StarMapService));
            Dictionary <string, object> deaths = (Dictionary <string, object>)starMapService.InvokeStatic("ParseStarMapDeaths", new object[] { response });

            Assert.IsNotNull(deaths);
            Assert.AreEqual(1068, (long?)deaths["total"]);
            Assert.AreEqual(31, (long?)deaths["week"]);
            Assert.AreEqual(4, (long?)deaths["day"]);
        }
Ejemplo n.º 13
0
        public void V2MasterPasswordIsUniqueTest()
        {
            string key1 = CalculateNewMasterPasswordKey(MASTERPASSWORD);
            string key2 = CalculateNewMasterPasswordKey(MASTERPASSWORD);

            Assert.AreNotEqual(key1, key2, "generated master password key always equals.");

            var accessor = new PrivateType(typeof(PasswordFunctions2));

            byte[] keySalt = (byte[])accessor.InvokeStatic("CreateRandomKeySalt", new Object[] {});
            key1 = CalculateV2Key(accessor, keySalt);
            key2 = CalculateV2Key(accessor, keySalt);
            Assert.AreEqual(key1, key2, "generated master password doesn't equal.");
        }
Ejemplo n.º 14
0
        public void HashPassword_ExampleString_returnEqual()
        {
            //arrange
            string password = "******";

            byte[]      expectedResult = { 161, 197, 195, 94, 68, 48, 156, 35, 26, 5, 53, 129, 72, 183, 200, 228, 65, 84, 166, 16, 193, 23, 17, 8, 130, 41, 177, 49, 198, 129, 144, 47 };
            PrivateType type           = new PrivateType(typeof(RSA));

            //act
            byte[] result = (byte[])type.InvokeStatic("generateHash", new [] { password });

            //assert
            CollectionAssert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 15
0
        public void GetMatchingDatabaseFieldAttribute_ShouldThrowException_WhenGivenNullProperty()
        {
            try
            {
                PropertyInfo nullProperty = default;

                PrivateType pt = new PrivateType(typeof(MatchingDatabaseFieldHelper));
                pt.InvokeStatic("GetMatchingDatabaseFieldAttribute", nullProperty);
            }
            catch (TargetInvocationException ex)
            {
                throw ex.InnerException;
            }
        }
        public void TestSerializeToString(string modelName)
        {
            ModelDoc2 doc      = OpenSWDocument(modelName);
            LinkNode  baseNode = Serialization.LoadBaseNodeFromModel(SwApp, doc, out bool error);

            Xunit.Assert.False(error);

            PrivateType serialization = new PrivateType(typeof(Serialization));
            string      newData       = (string)serialization.InvokeStatic(
                "SerializeToString", new object[] { baseNode });

            Xunit.Assert.NotNull(newData);
            Xunit.Assert.NotEmpty(newData);
        }
Ejemplo n.º 17
0
        public void ParseBoolParameterTest()
        {
            var udf = new PrivateType(typeof(UserDefinedFunctions));

            Assert.ThrowsException <ValidationError>(
                () => udf.InvokeStatic("ParseBoolParameter", "dummy", true));
            Assert.IsTrue((bool)udf.InvokeStatic("ParseBoolParameter", "", true));
            Assert.IsFalse((bool)udf.InvokeStatic("ParseBoolParameter", null, false));
            Assert.IsTrue((bool)udf.InvokeStatic("ParseBoolParameter", "TRUE", false));
            Assert.IsTrue((bool)udf.InvokeStatic("ParseBoolParameter", "true", false));
            Assert.IsFalse((bool)udf.InvokeStatic("ParseBoolParameter", "FALSE", true));
            Assert.IsFalse((bool)udf.InvokeStatic("ParseBoolParameter", "false", true));
        }
Ejemplo n.º 18
0
        public void SnLog_EventTypeProvider_Information()
        {
            var e = new Exception("E0");

            e = new TestException_Warning("E1", e);
            e = new Exception("E2", e);
            e = new TestException_Information("E3", e);
            e = new Exception("E4", e);

            //"GetEventType", e
            var snLogAcc = new PrivateType(typeof(SnLog));
            var actual   = (TraceEventType)snLogAcc.InvokeStatic("GetEventType", e);

            Assert.AreEqual(TraceEventType.Information, actual);
        }
Ejemplo n.º 19
0
        public void TruncateSelectedFields_AllFieldsNull_AddsNullValues()
        {
            Dictionary <BugField, string> bugFieldPairs = new Dictionary <BugField, string>();
            BugInformation bugInfo = new BugInformation();

            PrivateType privateAzureDevOpsBugReporting = new PrivateType(typeof(AzureDevOpsBugReporting));

            privateAzureDevOpsBugReporting.InvokeStatic("TruncateSelectedFields", bugInfo, bugFieldPairs);

            Assert.AreEqual(4, bugFieldPairs.Count);
            Assert.IsNull(bugFieldPairs[BugField.ProcessName]);
            Assert.IsNull(bugFieldPairs[BugField.Glimpse]);
            Assert.IsNull(bugFieldPairs[BugField.TestMessages]);
            Assert.IsNull(bugFieldPairs[BugField.RuleSource]);
        }
Ejemplo n.º 20
0
        public void Hermo_Parse_06()
        {
            var p = new PrivateType(typeof(Hermo));
            var x = (HermoReading)p.InvokeStatic("ParseLine", "108D742C0208007237004B46FFFF031025");

            Assert.AreEqual(0x720008022C748D10, x.Code);
            Assert.AreEqual(0x5E748512, x.Code32);
            Assert.AreEqual(0xDB66, x.Code16);
            Assert.AreEqual(0x10, x.FamilyId);
            Assert.AreEqual(0x0008022C748D, x.Serial);

            Assert.AreEqual(true, x.HasTemperature);
            Assert.AreEqual(27.25, x.Temperature);
            Assert.AreEqual(0.25, x.Resolution);
        }
Ejemplo n.º 21
0
        public void Hermo_Parse_0x10_17()
        {
            var p = new PrivateType(typeof(Hermo));
            var x = (HermoReading)p.InvokeStatic("ParseLine", "109A29130000003E09000705FFFF184EC4");

            Assert.AreEqual(0x3E00000013299A10, x.Code);
            Assert.AreEqual(0x2D299A10, x.Code32);
            Assert.AreEqual(0xB739, x.Code16);
            Assert.AreEqual(0x10, x.FamilyId);
            Assert.AreEqual(0x00000013299A, x.Serial);

            Assert.AreEqual(true, x.HasTemperature);
            Assert.AreEqual(4.25, x.Temperature);
            Assert.AreEqual(0.25, x.Resolution);
        }
Ejemplo n.º 22
0
        public void Hermo_Parse_01()
        {
            var p = new PrivateType(typeof(Hermo));
            var x = (HermoReading)p.InvokeStatic("ParseLine", "108D6A45020800AF3A004B46FFFF0B102F");

            Assert.AreEqual(unchecked ((Int64)0xAF000802456A8D10), x.Code);
            Assert.AreEqual(unchecked ((Int32)0xEA6A8512), x.Code32);
            Assert.AreEqual(0x6F78, x.Code16);
            Assert.AreEqual(0x10, x.FamilyId);
            Assert.AreEqual(0x000802456A8D, x.Serial);

            Assert.AreEqual(true, x.HasTemperature);
            Assert.AreEqual(28.75, x.Temperature);
            Assert.AreEqual(0.25, x.Resolution);
        }
Ejemplo n.º 23
0
        public void Hermo_Parse_04()
        {
            var p = new PrivateType(typeof(Hermo));
            var x = (HermoReading)p.InvokeStatic("ParseLine", "10C8DD540108007C2F004B46FFFF081078");

            Assert.AreEqual(0x7C00080154DDC810, x.Code);
            Assert.AreEqual(0x28DDC011, x.Code32);
            Assert.AreEqual(0xE8CC, x.Code16);
            Assert.AreEqual(0x10, x.FamilyId);
            Assert.AreEqual(0x00080154DDC8, x.Serial);

            Assert.AreEqual(true, x.HasTemperature);
            Assert.AreEqual(23.25, x.Temperature);
            Assert.AreEqual(0.25, x.Resolution);
        }
        public void TestLoadConfigFromStringXML(string modelName, int expNumLinks)
        {
            ModelDoc2   doc           = OpenSWDocument(modelName);
            PrivateType serialization = new PrivateType(typeof(Serialization));
            object      swAttObj      = serialization.InvokeStatic(
                "FindSWSaveAttribute", new object[] { doc, "URDF Export Configuration" });

            Xunit.Assert.NotNull(swAttObj);

            Attribute swAtt = (Attribute)swAttObj;
            Parameter param = swAtt.GetParameter("data");

            Xunit.Assert.NotNull(param);
            string data = param.GetStringValue();

            Xunit.Assert.NotNull(data);
            Xunit.Assert.NotEmpty(data);

            LinkNode baseNode = (LinkNode)serialization.InvokeStatic(
                "LoadConfigFromStringXML", new object[] { data });
            Link link = baseNode.GetLink();

            Xunit.Assert.Equal(expNumLinks, Common.GetCount(link));
        }
Ejemplo n.º 25
0
        public void Hermo_Parse_07()
        {
            var p = new PrivateType(typeof(Hermo));
            var x = (HermoReading)p.InvokeStatic("ParseLine", "2846185F0300003DC6014B467FFF0A1017");

            Assert.AreEqual(0x3D0000035F184628, x.Code);
            Assert.AreEqual(0x6218462B, x.Code32);
            Assert.AreEqual(0x2433, x.Code16);
            Assert.AreEqual(0x28, x.FamilyId);
            Assert.AreEqual(0x0000035F1846, x.Serial);

            Assert.AreEqual(true, x.HasTemperature);
            Assert.AreEqual(28.375, x.Temperature);
            Assert.AreEqual(0.0625, x.Resolution);
        }
Ejemplo n.º 26
0
        public void RollIPv4_UsingMethodWithAddressFamilyAsParameter_ReturnsValidIPv4()
        {
            //Arrange
            Regex regexForIPv4 = new Regex(@"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$");

            PrivateType IPGenerator_PrivateType = new PrivateType(typeof(IPGenerator));

            object[] parameterValues = { 127 };

            //Act
            var result = Convert.ToString(IPGenerator_PrivateType.InvokeStatic("RollIPv4", parameterValues));

            //Assert
            Assert.IsTrue(regexForIPv4.IsMatch(result));
        }
Ejemplo n.º 27
0
        public void ApplyDecodingStepOnUnknownOperatorThrowsArgumentOutOfRangeException()
        {
            const string invalidOperator = "%";

            try
            {
                var solverType = new PrivateType(typeof(ChallengeSolver));
                solverType.InvokeStatic("ApplyDecodingStep", 323D, Tuple.Create(invalidOperator, 32D));
            }
            //We're calling this with reflection, so we have to throw up the TargetInvocationException to represent what would actually occur.
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
        }
Ejemplo n.º 28
0
        public void GetMappingElement_Scenerio_Result()
        {
            //------------Setup for test-------------------------
            var pr    = new PrivateType(typeof(Dev2Logger));
            var value = pr.InvokeStatic("GetMappingElement", "Level0", "ERROR");

            //------------Execute Test---------------------------
            //------------Assert Results-------------------------
            Assert.IsNotNull(value);
            Assert.IsNotNull(value);
            Assert.AreEqual(value.ToString(), @"<mapping>
  <level value=""Level0"" />
  <eventLogEntryType value=""ERROR"" />
</mapping>");
        }
Ejemplo n.º 29
0
        public void Hermo_Parse_0x28_17()
        {
            var p = new PrivateType(typeof(Hermo));
            var x = (HermoReading)p.InvokeStatic("ParseLine", "2824F76B000000872C014B467FFF041014");

            Assert.AreEqual(unchecked ((Int64)0x870000006BF72428), x.Code);
            Assert.AreEqual(unchecked ((Int32)0xECF72428), x.Code32);
            Assert.AreEqual(0xC8DF, x.Code16);
            Assert.AreEqual(0x28, x.FamilyId);
            Assert.AreEqual(0x0000006BF724, x.Serial);

            Assert.AreEqual(true, x.HasTemperature);
            Assert.AreEqual(18.75, x.Temperature);
            Assert.AreEqual(0.0625, x.Resolution);
        }
Ejemplo n.º 30
0
        public void Hermo_Parse_05()
        {
            var p = new PrivateType(typeof(Hermo));
            var x = (HermoReading)p.InvokeStatic("ParseLine", "104C5F450208005139004B46FFFF0410F2");

            Assert.AreEqual(0x51000802455F4C10, x.Code);
            Assert.AreEqual(0x145F4412, x.Code32);
            Assert.AreEqual(0x504D, x.Code16);
            Assert.AreEqual(0x10, x.FamilyId);
            Assert.AreEqual(0x000802455F4C, x.Serial);

            Assert.AreEqual(true, x.HasTemperature);
            Assert.AreEqual(28.25, x.Temperature);
            Assert.AreEqual(0.25, x.Resolution);
        }
Ejemplo n.º 31
0
        public void TruncateSelectedFields_AllFieldsNull_AddsNullValues()
        {
            Dictionary <IssueField, string> issueFieldPairs = new Dictionary <IssueField, string>();
            IssueInformation issueInfo = new IssueInformation();

            PrivateType privateFileIssueHelpers = new PrivateType(typeof(FileIssueHelpers));

            privateFileIssueHelpers.InvokeStatic("TruncateSelectedFields", issueInfo, issueFieldPairs);

            Assert.AreEqual(4, issueFieldPairs.Count);
            Assert.IsNull(issueFieldPairs[IssueField.ProcessName]);
            Assert.IsNull(issueFieldPairs[IssueField.Glimpse]);
            Assert.IsNull(issueFieldPairs[IssueField.TestMessages]);
            Assert.IsNull(issueFieldPairs[IssueField.RuleSource]);
        }
        public void TestProgramMainAll()
        {
            PrivateType privateTypeObject = new PrivateType(typeof(Program));

            privateTypeObject.InvokeStatic("ProcessInput", "c 5 3");
            privateTypeObject.InvokeStatic("ProcessInput", "r 2 1 5 3");
            privateTypeObject.InvokeStatic("ProcessInput", "b 2 2 o");

            using (ConsoleOutput consoleOutput = new ConsoleOutput())
            {
                privateTypeObject.InvokeStatic("ProcessInput", "l 3 1 3 3");

                StringBuilder sb = new StringBuilder();
                sb.Append("-------").Append(Environment.NewLine);
                sb.Append("|\0oxoo|").Append(Environment.NewLine);
                sb.Append("|\0ox\0o|").Append(Environment.NewLine);
                sb.Append("|\0oxoo|").Append(Environment.NewLine);
                sb.Append("-------");

                string expected = sb.ToString();

                Assert.AreEqual <string>(expected, consoleOutput.GetOutput().Trim());
            }
        }
Ejemplo n.º 33
0
        public void ExtractDataToConvertCorrectFormat()
        {
            StreamReader streamReader = MockStreamReaderService.MockContentFile("EUR;550;JPY");

            DataToConvert dataToConvert = (DataToConvert)_privateType.InvokeStatic("ExtractDataToConvert", streamReader);

            Assert.AreEqual(dataToConvert.D1, "EUR");
            Assert.AreEqual(dataToConvert.M, (uint)550);
            Assert.AreEqual(dataToConvert.D2, "JPY");
        }
        public void GetReportQueryNode_ValuesNodeNotEmpty_ReturnExpectedContent()
        {
            // Arrange
            var expectedText = $"({DummyString}Text = '{DummyString}' )";
            var spWeb        = new ShimSPWeb().Instance;
            var xmlNode      = new ShimXmlNode(new XmlDocument()).Instance;
            var spList       = new ShimSPList
            {
                FieldsGet = () => new ShimSPFieldCollection
                {
                    GetFieldByInternalNameString = name => new ShimSPField
                    {
                        TypeGet = () => SPFieldType.User
                    }
                }
            }.Instance;
            var privateType = new PrivateType(typeof(ReportingData));

            ShimXmlDocument.AllInstances.NameGet            = _ => "Contains";
            ShimXmlNode.AllInstances.SelectSingleNodeString =
                (_, nodeName) => new ShimXmlNode(new XmlDocument())
            {
                AttributesGet = () => new ShimXmlAttributeCollection
                {
                    ItemOfGetString = attrName => new ShimXmlAttribute
                    {
                        ValueGet = () => "Dummy"
                    }
                }
            }.Instance;
            ShimXmlNode.AllInstances.SelectNodesString = (_, name) =>
            {
                var document = new XmlDocument();
                var element  = document.CreateElement("Dummy");
                element.InnerText = "Dummy";
                document.AppendChild(element);
                return(document.ChildNodes);
            };
            var args = new object[] { spWeb, xmlNode, spList };

            // Act
            var result = privateType.InvokeStatic(GetReportQueryNodeMethodName, args) as string;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNullOrEmpty(),
                () => result.ShouldBe(expectedText));
        }
        private void DoFailureTest(Dictionary <object[], string> testData, string method)
        {
            PrivateType fontConfigFile = new PrivateType(typeof(FontConfigFile));

            foreach (var failure in testData)
            {
                try
                {
                    fontConfigFile.InvokeStatic(method, failure.Key);
                }
                catch (Exception e)
                {
                    Assert.AreEqual(failure.Value, e.Message);
                }
            }
        }
Ejemplo n.º 36
0
        public void GetAddress_Given_Null_Source_And_NoRelativeUri_Should_Return_relativeUri()
        {
            //------------Setup for test-------------------------
            var webSource = new PrivateType(typeof(WebSources));

            //------------Execute Test---------------------------
            object[] args = { null, string.Empty };
            var      invokeStaticResults = webSource.InvokeStatic("GetAddress", args);

            //------------Assert Results-------------------------
            Assert.IsNotNull(invokeStaticResults);
            var results = invokeStaticResults as string;

            Assert.IsNotNull(results);
            Assert.IsTrue(string.IsNullOrEmpty(results));
        }
Ejemplo n.º 37
0
        public void WebSources_GetAddress_Given_Null_Source_And_relativeUri_Should_Return_relativeUri()
        {
            //------------Setup for test-------------------------
            var webSource = new PrivateType(typeof(WebSources));

            //------------Execute Test---------------------------
            object[] args = { null, "some url" };
            var      invokeStaticResults = webSource.InvokeStatic("GetAddress", args);

            //------------Assert Results-------------------------
            Assert.IsNotNull(invokeStaticResults);
            var results = invokeStaticResults as string;

            Assert.IsNotNull(results);
            Assert.AreEqual("some url", results);
        }
Ejemplo n.º 38
0
		public void TestNullate01() {
			PrivateType nullateClass = new PrivateType(typeof(CFGtoCNF));
			var production = CFGParser.Production("<S> -> <A> 'b' <B> [1]");
			var nullableDictionary = new Dictionary<Nonterminal, double> {
				{ Nonterminal.Of("A"), 0.5 },
				{ Nonterminal.Of("B"), 0.2 }
			};

			var actualList = (List<Production>)nullateClass.InvokeStatic("Nullate", new object[] { production, nullableDictionary });
			var actual = new HashSet<string>(actualList.Select((p) => p.ToString()));
			var expected = new HashSet<string> {
				CFGParser.Production("<S> -> <A> 'b' <B> [0.4]").ToString(),
				CFGParser.Production("<S> -> <A> 'b' [0.1]").ToString(),
				CFGParser.Production("<S> -> 'b' <B> [0.4]").ToString(),
				CFGParser.Production("<S> -> 'b' [0.1]").ToString(),
			};
			Assert.IsTrue(actual.SetEquals(expected));
		}
 public void TestFlushDetection()
 {
     var handEvaluator = new PrivateType(typeof(HandEvaluator));
     Assert.IsTrue((bool)handEvaluator.InvokeStatic("IsFlush", Flush.Cards), "Flush Error", "Failed to identify a flush.");
     Assert.IsFalse((bool)handEvaluator.InvokeStatic("IsFlush", StraightNoAce.Cards), "Flush Error", "Falsely identified a non flush hand as flush.");
 }
 public void TestHandRankings()
 {
     var handEvaluator = new PrivateType(typeof(HandEvaluator));
     Assert.AreEqual(9, (int)handEvaluator.InvokeStatic("GetHandType", StraightFlush.Cards), "Point Error", "Straight flush did not get the appropriate number of points");
     Assert.AreEqual(8, (int)handEvaluator.InvokeStatic("GetHandType", FourOfAKindHighCard.Cards), "Point Error", "Four of a kind did not get the appropriate point value.");
     Assert.AreEqual(7, (int)handEvaluator.InvokeStatic("GetHandType", FullHouse.Cards), "Point Error", "Full house did not get the appropriate point value.");
     Assert.AreEqual(6, (int)handEvaluator.InvokeStatic("GetHandType", Flush.Cards), "Point Error", "Flush did not get the appropriate point value.");
     Assert.AreEqual(5, (int)handEvaluator.InvokeStatic("GetHandType", StraightNoAce.Cards), "Point Error", "Straight did not get the appropriate point value.");
     Assert.AreEqual(4, (int)handEvaluator.InvokeStatic("GetHandType", ThreeOfAKind.Cards), "Point Error", "Three of a kind did not get the appropriate point value.");
     Assert.AreEqual(3, (int)handEvaluator.InvokeStatic("GetHandType", TwoPair.Cards), "Point Error", "Two pair did not get the appropriate point value.");
     Assert.AreEqual(2, (int)handEvaluator.InvokeStatic("GetHandType", OnePair.Cards), "Point Error", "Pair did not get the appropriate point value.");
     Assert.AreEqual(1, (int)handEvaluator.InvokeStatic("GetHandType", HighCard.Cards), "Point Error", "High card did not get the appropriate point value.");
 }
Ejemplo n.º 41
0
        public void NumberEncoder_Test()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));
            short input = -1;
            ushort expected = 65534; // 11111111 11111110

            ushort output = (ushort)pt.InvokeStatic("_numberEncoder", input);
            
            Assert.AreEqual(expected, output);
        }
Ejemplo n.º 42
0
        public void Flush_Test()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));

            BitList bl = new BitList();
            bl.Add(true);
            bl.Add(true);
            bl.Add(false);

            byte[] output = (byte[]) pt.InvokeStatic("_flush", bl);

            byte[] expected = new byte[1] {192}; // 11000000

            Assert.AreEqual(expected, output);

        }
Ejemplo n.º 43
0
        public void Bitcost_Test()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));
            short input = 2;

            byte expected = 2;

            byte output = (byte)pt.InvokeStatic("_bitCost", input);

            Assert.AreEqual(expected, output);
        }
Ejemplo n.º 44
0
        public void UShortToBits_Test()
        {
            BitList bitList = new BitList();
            ushort input = 3;
            byte inputLen = 2;
            
            PrivateType pt = new PrivateType(typeof(JpegImage));

            pt.InvokeStatic("_ushortToBits", new object[] {bitList, input, inputLen});

            BitList expectedBitList = new BitList();
            expectedBitList.Add(true);
            expectedBitList.Add(true);

            Assert.AreEqual(expectedBitList, bitList);
        }
 public void TestTwoPairDetection()
 {
     var handEvaluator = new PrivateType(typeof(HandEvaluator));
     Assert.IsTrue((bool)handEvaluator.InvokeStatic("ContainsTwoPairs", TwoPair.Cards), "Two pair error", "Failed to detect two pairs in a hand.");
     Assert.IsFalse((bool)handEvaluator.InvokeStatic("ContainsTwoPairs", OnePair.Cards), "Two pair error", "Detected two pair when given one pair");
     Assert.IsFalse((bool)handEvaluator.InvokeStatic("ContainsTwoPairs", HighCard.Cards), "Two pair error", "Detected a high card hand as two pairs.");
 }
Ejemplo n.º 46
0
        public void SplitToChannels_Test()
        {
            Bitmap b = new Bitmap(2,2);
            b.SetPixel(0,0, Color.Black);   // R = 0,   G = 0,   B = 0 
            b.SetPixel(1,0, Color.Green);   // R = 0,   G = 128, B = 0
            b.SetPixel(0,1, Color.Red);     // R = 128, G = 0,   B = 0
            b.SetPixel(1,1,Color.Blue);     // R = 0,   G = 0,   B= 128

            PrivateType pt = new PrivateType(typeof(JpegImage));


            sbyte[][,] returnedChannels = (sbyte[][,])pt.InvokeStatic("_splitToChannels", b);

            sbyte[,] ch1 = {
                {-128, -51}, {-52, -98}
            };
            sbyte[,] ch2 = {
                {0, -43}, {-42, 127}
            };
            sbyte[,] ch3 = {
                {0, 127}, {-53, -20}
            };

            sbyte[][,] expectedChannels = {ch1, ch2, ch3};

            Assert.AreEqual(expectedChannels, returnedChannels);
        }
Ejemplo n.º 47
0
        public void AddEdge_Test()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));

            Vertex
                v1 = new Vertex(0, 1, 0, 4),
                v2 = new Vertex(2, 3, 2, 4),
                v3 = new Vertex(4, 5, 3, 4),
                v4 = new Vertex(6, 7, 3, 4),
                v5 = new Vertex(8, 9, 4, 4),
                v6 = new Vertex(10, 11, 5, 4);

            Graph inputGraph = new Graph();
            inputGraph.Vertices.AddRange(new List<Vertex>() { v1, v2, v3, v4, v5, v6 });

            int inputThreshold = 5;

            pt.InvokeStatic("_addEdge", new object[] {true, false, v1, v2, inputThreshold, inputGraph});    //pass
            pt.InvokeStatic("_addEdge", new object[] {true, true, v3, v4, inputThreshold, inputGraph});     //pass
            pt.InvokeStatic("_addEdge", new object[] {false, true, v5, v6, inputThreshold, inputGraph});    //fail

            Graph expectedGraph = new Graph();

            expectedGraph.Edges.Add(new Edge(v1, v2, 3, true, false));
            expectedGraph.Edges.Add(new Edge(v3, v4, 2, true, true));

            Assert.AreEqual(expectedGraph.Edges, inputGraph.Edges);
        }
 public void TestSetDetection()
 {
     var handEvaluator = new PrivateType(typeof(HandEvaluator));
     Assert.IsTrue((bool)handEvaluator.InvokeStatic("ContainsSetOfSizeX", 4, FourOfAKindHighCard.Cards), "Set Identification error.", "Failed to properly identify a four of a kind.");
     Assert.IsFalse((bool)handEvaluator.InvokeStatic("ContainsSetOfSizeX", 2, StraightNoAce.Cards), "Set Identification error.", "Detected a two of a kind when given a straight.");
 }
Ejemplo n.º 49
0
        public void Quantization_Test()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));
            JpegImage ji = new JpegImage(new Bitmap(200, 100), 100, 4);


            float[,] inputValues = new float[8, 8];
            int i = 0;
            for (int x = 0; x < 8; x++) //Fill input value with values from 0 to 63
            {
                for (int y = 0; y < 8; y++)
                {
                    inputValues[x, y] = i++;
                }
            }

            short[,] quantizedValues =
                (short[,]) pt.InvokeStatic("_quantization", new object[] {inputValues, ji.YQuantizationTable});

            short[,] expectedQuantizedValues = new short[8, 8]
            {
                {0, 1, 2, 3, 2, 1, 1, 0},
                {8, 9, 10, 5, 6, 3, 1, 1},
                {16, 17, 9, 9, 5, 3, 2, 2},
                {12, 12, 8, 9, 4, 3, 3, 2},
                {10, 11, 6, 5, 4, 3, 3, 2},
                {8, 5, 6, 4, 3, 3, 3, 3},
                {8, 7, 6, 5, 4, 3, 3, 4},
                {8, 9, 8, 8, 6, 5, 5, 5},
            };

            Assert.AreEqual(expectedQuantizedValues, quantizedValues);
        }
Ejemplo n.º 50
0
        public void C_Test_i1_j1()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));

            float returnedC = (float)pt.InvokeStatic("_c", new object[] { 1, 1 });

            Assert.AreEqual(0.25f, returnedC);
        }
Ejemplo n.º 51
0
        public void DiscreteCosineTransform_Test()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));
            JpegImage ji = new JpegImage(new Bitmap(200, 100), 100, 4);

            float[,] inputBlock8 = new float[8, 8];
            int i = 0;
            for (int x = 0; x < 8; x++) //Fill input value with values from 0 to 63
            {
                for (int y = 0; y < 8; y++)
                {
                    inputBlock8[x, y] = i++;
                }
            }

            float[,] returnedCosineValues = (float[,])pt.InvokeStatic("_discreteCosineTransform", inputBlock8);

            float[,] expectedCosineValues = new float[8, 8]
            {
                {252f, -18.220953f, -1.3045323E-07f, -1.90474725f, 1.78540418E-07f, -0.568218122f, -8.80875195E-09f, -0.143401206f},
                {-145.767609f, 2.41847101E-06f, 8.53143945E-07f, 1.44885166E-06f, 1.03676985E-06f, -1.5390215E-07f, -2.55802661E-07f, -9.47974854E-08f},
                {-2.99147609E-06f, 5.62151536E-06f, -1.10848976E-06f, -3.00187935E-07f, 2.10143571E-06f, -5.08922085E-07f, -6.90155488E-08f, 9.28238705E-07f},
                {-15.2379627f, 4.95177403E-07f, -1.25386225E-06f, -2.32657641E-07f, -7.20322817E-07f, 4.82752E-07f, -1.97521246E-07f, 6.68256234E-07f},
                {-1.72880823E-06f, -8.70578845E-07f, -7.59587181E-07f, 1.18702587E-06f, 2.07287385E-07f, 6.64636985E-08f, 1.24796173E-07f, -2.74013161E-07f},
                {-4.54574156f, -2.06125083E-06f, 1.39842655E-06f, 5.91484728E-09f, -8.87210604E-07f, -3.22430438E-09f, 1.63273896E-07f, -2.61182095E-07f},
                {5.71323699E-06f, 2.60522029E-06f, 4.07821602E-07f, 7.56153099E-07f, -8.28878115E-07f, 1.63273896E-07f, -2.87587607E-08f, 4.81403617E-07f},
                {-1.1472187f, -1.5253089E-06f, 1.64349444E-06f, 4.29837684E-07f, -5.12431711E-07f, 8.11701511E-07f, 1.23775763E-07f, 7.26117264E-07f},
            };
            GlobalSettings.DefaultFloatingPointTolerance = 0.00001;

            
            Assert.That(expectedCosineValues, Is.EquivalentTo(returnedCosineValues));
        }
Ejemplo n.º 52
0
        public void Block16ToBlock8_Test() 
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));
            

            float[,] inputValues = new float[16, 16];
            int i = 0;
            for (int x = 0; x < 16; x++) //Fill input value with values from 0 to 255
            {
                for (int y = 0; y < 16; y++)
                {
                    inputValues[x, y] = i++;
                }
            }

            float[,] returnedBlock8 = (float[,]) pt.InvokeStatic("_block16ToBlock8", new object[] {inputValues, 1});

            float[,] expectedBlock8 = new float[8, 8]
            {
                {128,  129f, 130f, 131f, 132f, 133f, 134f, 135f},
                {144f, 145f, 146f, 147f, 148f, 149f, 150f, 151f},
                {160f, 161f, 162f, 163f, 164f, 165f, 166f, 167f},
                {176f, 177f, 178f, 179f, 180f, 181f, 182f, 183f},
                {192f, 193f, 194f, 195f, 196f, 197f, 198f, 199f},
                {208f, 209f, 210f, 211f, 212f, 213f, 214f, 215f},
                {224f, 225f, 226f, 227f, 228f, 229f, 230f, 231f},
                {240f, 241f, 242f, 243f, 244f, 245f, 246f, 247f},
            };

            Assert.AreEqual(expectedBlock8, returnedBlock8);
        }
Ejemplo n.º 53
0
        public void DownSample_Test()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));
            float[,] inputValues = new float[16, 16];
            int i = 0;
            for (int x = 0; x < 16; x++) //Fill input value with values from 1 to 255
            {
                for (int y = 0; y < 16; y++)
                {
                    inputValues[x, y] = i++;
                }
            }

            float[,] downSampleValues = (float[,])pt.InvokeStatic("_downSample", inputValues);

            float[,] expectedDownSampledValues = new float[8, 8]
            {
                {8.5f,  10.5f, 12.5f, 14.5f, 16.5f, 18.5f, 20.5f, 22.5f},
                {40.5f, 42.5f, 44.5f, 46.5f, 48.5f, 50.5f, 52.5f, 54.5f},
                {72.5f, 74.5f, 76.5f, 78.5f, 80.5f, 82.5f, 84.5f, 86.5f},
                {104.5f, 106.5f, 108.5f, 110.5f, 112.5f, 114.5f, 116.5f, 118.5f},
                {136.5f, 138.5f, 140.5f, 142.5f, 144.5f, 146.5f, 148.5f, 150.5f},
                {168.5f, 170.5f, 172.5f, 174.5f, 176.5f, 178.5f, 180.5f, 182.5f},
                {200.5f, 202.5f, 204.5f, 206.5f, 208.5f, 210.5f, 212.5f, 214.5f},
                {232.5f, 234.5f, 236.5f, 238.5f, 240.5f, 242.5f, 244.5f, 246.5f},
            };

            Assert.AreEqual(expectedDownSampledValues, downSampleValues);
        }
 public void TestStraightDetection()
 {
     var handEvaluator = new PrivateType(typeof(HandEvaluator));
     Assert.IsFalse((bool)handEvaluator.InvokeStatic("IsStraight", FourOfAKindHighCard.Cards), "Straight Error", "Evaluated a hand with duplicate values as straight.");
     Assert.IsTrue((bool)handEvaluator.InvokeStatic("IsStraight", StraightNoAce.Cards), "Straight Error", "Failed to detect a standard straight");
 }
Ejemplo n.º 55
0
        public void ForceSampleChange()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));
            Vertex
                inputVertex = new Vertex(0, 1, 0, 4),
                expectedVertex = new Vertex(-1, 1, 0, 4);

            pt.InvokeStatic("_forceSampleChange", inputVertex);

            Assert.AreEqual(expectedVertex.ToString(), inputVertex.ToString());
        }
Ejemplo n.º 56
0
        public void RefactorGraph_Test() //TODO: fix this test
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));

            Vertex
                v1 = new Vertex(0, 1, 0, 4),
                v2 = new Vertex(2, 3, 2, 4),
                v3 = new Vertex(4, 5, 3, 4),
                v4 = new Vertex(6, 7, 3, 4),
                v5 = new Vertex(8, 9, 4, 4),
                v6 = new Vertex(10, 11, 5, 4);
            Edge
                e1 = new Edge(v1, v2, 1, true, false),
                e2 = new Edge(v3, v4, 2, true, true),
                e3 = new Edge(v5, v6, 2, false, true);

            Graph inputGraph = new Graph();
            Graph sad = new Graph();
            inputGraph.Edges.Add(e1);
            inputGraph.Edges.Add(e2);
            inputGraph.Edges.Add(e3);
            sad.Edges.Add(e1);
            sad.Edges.Add(e2);
            sad.Edges.Add(e3);
            sad.Vertices.AddRange(new List<Vertex>() { v1, v2, v3, v4, v5, v6 });
            inputGraph.Vertices.AddRange(new List<Vertex>() { v1, v2, v3, v4, v5, v6 });

            
            pt.InvokeStatic("_refactorGraph", inputGraph);
            
            Assert.AreEqual(sad.Vertices, inputGraph.Vertices);
        }
Ejemplo n.º 57
0
        public void CopyBitmap_Test()
        {
            Bitmap b = new Bitmap(1, 1);
            b.SetPixel(0, 0, Color.Black);
            Bitmap testBitmapIn = new Bitmap(b, 200, 100);

            PrivateType pt = new PrivateType(typeof(JpegImage));

            Bitmap copiedBitmap = (Bitmap)pt.InvokeStatic("_copyBitmap", new object[] {testBitmapIn, 200, 100});
 
            Assert.AreEqual(testBitmapIn.GetPixel(100, 50), copiedBitmap.GetPixel(100, 50));
        }
Ejemplo n.º 58
0
        public void TestPrivates()
        {
            // Note how we test private instance method with PrivateObject
            // https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.privateobject.aspx
            var po = new PrivateObject(new SomeBusinessLogicClass());
            Assert.AreEqual(3, po.Invoke("SomeInternalLogic", 1, 2));

            // Note how we test private static methods with PrivateType
            // https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.privatetype.aspx
            var pt = new PrivateType(typeof(SomeBusinessLogicClass));
            Assert.AreEqual(42, pt.InvokeStatic("SomeInternalStaticLogic"));

            // For PrivateObject and PrivateType, be VERY CAREFUL with parameters.
            // If you use the wrong type, you will get strange erros as methods
            //   cannot be found.
        }
Ejemplo n.º 59
0
        public void SwapVertexData()
        {
            PrivateType pt = new PrivateType(typeof(JpegImage));
            Vertex
                inputV1 = new Vertex(0, 1, 0, 4),
                inputV2 = new Vertex(2, 3, 0, 4),
                expectedV1 = new Vertex(2, 1, 0, 4),
                expectedV2 = new Vertex(0, 3, 0, 4);

            Edge
                inputE1 = new Edge(inputV1, inputV2, 0, true, true),
                expectedE1 = new Edge(expectedV1, expectedV2, 0, true, true);

            pt.InvokeStatic("_swapVertexData", inputE1);

            Assert.AreEqual(expectedE1.ToString(), inputE1.ToString());
        }
Ejemplo n.º 60
-1
		public async Task DatabaseTest()
		{
			// Note that this test really accesses a database. So we need a database
			// (localdb) on the build server.

			var pt = new PrivateType(typeof(SimpleOwinDatabaseSample.Startup));
			var tables = await (pt.InvokeStatic("GetTableNamesAsync") as Task<IEnumerable<string>>);
			Assert.IsNotNull(tables);
			Assert.IsTrue(tables.Count() > 0);
		}