public void Init() { PrivateType p = new PrivateType(typeof(Dev2DataLanguageParser)); var cache = p.GetStaticField("_expressionCache") as ConcurrentDictionary<string, IList<IIntellisenseResult>>; Assert.IsNotNull(cache); cache.Clear(); var cache2 = p.GetStaticField("_payloadCache") as ConcurrentDictionary<Tuple<string, string>, IList<IIntellisenseResult>>; Assert.IsNotNull(cache2); cache2.Clear(); Monitor.Enter(DataListSingletonTest.DataListSingletonTestGuard); var testEnvironmentModel = ResourceModelTest.CreateMockEnvironment(); _resourceModel = new ResourceModel(testEnvironmentModel.Object) { ResourceName = "test", ResourceType = ResourceType.Service, DataList = @" <DataList> <Scalar/> <Country/> <State /> <City> <Name/> <GeoLocation /> </City> </DataList> " }; IDataListViewModel setupDatalist = new DataListViewModel(); DataListSingleton.SetDataList(setupDatalist); DataListSingleton.ActiveDataList.InitializeDataListViewModel(_resourceModel); }
public void Initialize() { PrivateType pt = new PrivateType(typeof(SQLiteRepositoryClient)); pt.SetStaticField("dataSource", filename); wait = new AutoResetEvent(false); }
public void MyTestCleanup() { PrivateType privateWindowType = new PrivateType(typeof(VSWindows)); privateWindowType.SetStaticFieldOrProperty("instance", null); this.serviceProvider = null; }
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 InstanceTest() { try { InvisibleForm actual; actual = InvisibleForm.Instance; Assert.IsNotNull(actual, "InvisibleForm.Instance returned null"); // Reset and try again PrivateType invisibleForm = new PrivateType(typeof(InvisibleForm)); invisibleForm.SetStaticFieldOrProperty("instanceForm", null); actual = InvisibleForm.Instance; Assert.IsNotNull(actual, "InvisibleForm.Instance returned null"); Assert.AreSame(actual, invisibleForm.GetStaticFieldOrProperty("instanceForm"), "Second call to the property should return the same opbject instance."); Form f = actual as Form; Assert.IsFalse(f.Visible, "InvisibleForm should not be visible"); } catch (Exception ex) { // Use try catch to test a workaround on CI build (AppVeyor) Console.WriteLine(ex.Message); } }
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 GetPublicStaticPropertyValue() { dynamic subjectPO = new PrivateType<Subject>(); bool actual = subjectPO.publicStaticProperty; Assert.IsFalse(actual); }
protected TestBaseClass(object instanceToTest, Type typeToTest, int? presentationMethodID) { if (instanceToTest != null) InstanceToTest = new PrivateObject(instanceToTest); if (typeToTest != null) TypeToTest = new PrivateType(typeToTest); }
public void TestGetApiURL() { PrivateType grinder = new PrivateType(typeof(MeatGrinder)); PrivateObject obj = new PrivateObject(grinder); var retval = obj.Invoke("GetApiURL"); Assert.AreEqual(1, 1); }
public void GetPublicStaticFieldValue() { dynamic subjectPO = new PrivateType<Subject>(); int actual = subjectPO.publicStaticField; Assert.AreEqual(Subject.FieldInitialValue, actual); }
public void TestCountBulls() { bool[] isBull = new bool[4]; PrivateType pr = new PrivateType(typeof(Game)); pr.SetStaticFieldOrProperty("secretNumberAsString", "1234"); int res = Game.CountBulls("1235", 0, isBull); Assert.AreEqual(3, res); }
public void InvokePrivateMethodThatReturnsBooleanWithParameter() { dynamic subjectPO = new PrivateType<Subject>(); bool result = subjectPO.privateStaticMethodThatReturnsBooleanWithParameter(true); Assert.IsTrue(result); }
/// <summary> /// Injects current UTC time as fixed constant as replacement of DateTime.UtcNow for testing purposes /// </summary> internal static void SetTestDateTime() { var moment = new PrivateType(typeof(Moment)); var current = DateTime.UtcNow; // reduce precision to seconds, because Ticks may be extracted by SQL server DateTime precise = new DateTime(current.Year, current.Month, current.Day, current.Hour, current.Minute, current.Second); var customMoment = new InjectionDateTime { UtcNow = precise }; moment.SetStaticField("service", customMoment); }
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); }
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); }
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(); }
public void GetConfigurationIndependentPropertyPagesTest() { Guid[] expected = new Guid[] { typeof(GeneralPropertyPage).GUID }; Guid[] actual; PrivateType type = new PrivateType(typeof(MyCustomProjectNode)); PrivateObject obj = new PrivateObject(projectNode, type); actual = (Guid[])obj.Invoke("GetConfigurationIndependentPropertyPages", new object[] { }); CollectionAssert.AreEqual(expected, actual, "IndependentPropertyPages not correctly set"); }
public void TestCountHits() { bool[] isBull = new bool[4]; bool[] isCow = new bool[10]; PrivateType pr = new PrivateType(typeof(Game)); pr.SetStaticFieldOrProperty("secretNumberAsString", "1234"); int bulls = Game.CountBulls("1234", 0, isBull); int cows = Game.CountCows("1234", 0, isBull, isCow); Assert.AreEqual(4, bulls); Assert.AreEqual(0, cows); }
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."); }
public void GameTestCurrentHits() { PrivateType pr = new PrivateType(typeof(Game)); pr.SetStaticFieldOrProperty("secretNumberAsString", "1234"); StringWriter sw = new StringWriter(); Console.SetOut(sw); Game.RevealCurrentHits("1234"); var result = sw.ToString(); var expected = String.Format("Wrong number! Bulls: 4, Cows: 0!{0}{0}", Environment.NewLine); Assert.AreEqual(expected, result); }
public void MyTestCleanup() { try { PrivateType instanceForm = new PrivateType(typeof(InvisibleForm)); instanceForm.SetStaticFieldOrProperty("instanceForm", null); } catch (Exception ex) { // Use try catch to test a workaround on CI build (AppVeyor) Console.WriteLine(ex.Message); } }
public void Cleanup() { try { PrivateType pt = new PrivateType(typeof(Taskboard.Apps.TaskboardApp)); pt.SetStaticField("_applcation", null); wait.Dispose(); File.Delete(filename); } catch(Exception) { } }
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 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 InstanceTest() { InvisibleForm actual; actual = InvisibleForm.Instance; Assert.IsNotNull(actual, "InvisibleForm.Instance returned null"); // Reset and try again PrivateType invisibleForm = new PrivateType(typeof(InvisibleForm)); invisibleForm.SetStaticFieldOrProperty("instanceForm", null); actual = InvisibleForm.Instance; Assert.IsNotNull(actual, "InvisibleForm.Instance returned null"); Assert.AreSame(actual, invisibleForm.GetStaticFieldOrProperty("instanceForm"), "Second call to the property should return the same opbject instance."); Form f = actual as Form; Assert.IsFalse(f.Visible, "InvisibleForm should not be visible"); }
public void CreateProjectTest() { int actual; int expected = 1; MyCustomProjectFactory customProjectFactory = new MyCustomProjectFactory(customProjectPackage); base.SetMsbuildEngine(customProjectFactory); ((IVsProjectFactory)customProjectFactory).CanCreateProject(projectFile, 2, out actual); Assert.AreEqual(expected, actual, "Cannot create project"); PrivateType type = new PrivateType(typeof(MyCustomProjectFactory)); PrivateObject obj = new PrivateObject(customProjectFactory, type); MyCustomProjectNode projectNode = (MyCustomProjectNode)obj.Invoke("PreCreateForOuter", new object[] { IntPtr.Zero }); Assert.IsNotNull(projectNode, "Cannot create project"); }
public void TestUI_DefaultHttpHandler_GeneratesDefaultPage() { PageInformation pageInformation = new PageInformation(); PrivateType privateDefaultHttpHandler = new PrivateType(typeof(DefaultHttpHandler)); privateDefaultHttpHandler.SetStaticField("_hostPath", new Lazy<string>(() => { return ""; })); try { string page = DefaultHttpHandler.GenerateDefaultPage(pageInformation); Assert.IsNotNull(page, "Page is expected to generate correctly"); Assert.IsTrue(page.Length > 0, "Page is expected to contain content"); } catch (Exception) { Assert.Fail("GenerateDefaultPage should not throw exceptions"); } }
public void CalculateCosineCoefficients_Test() { PrivateType pt = new PrivateType(typeof(JpegImage)); JpegImage ji = new JpegImage(new Bitmap(200, 100), 100, 4); //Constructor calls calcCosineCoef float[,] CosCoef = (float[,])pt.GetStaticField("CosinesCoefficients"); float[,] ExpectedCosCoef = new float[8, 8] { {1f, 0.980785251f, 0.9238795f, 0.8314696f, 0.707106769f, 0.555570245f, 0.382683426f, 0.195090324f}, {1f, 0.8314696f, 0.382683426f, -0.195090324f, -0.707106769f, -0.980785251f, -0.9238795f, -0.555570245f}, {1f, 0.555570245f, -0.382683426f, -0.980785251f, -0.707106769f, 0.195090324f, 0.923879504f, 0.831469595f}, {1f, 0.195090324f, -0.923879504f, -0.555570245f, 0.707106769f, 0.831469595f, -0.382683426f, -0.980785251f}, {1f, -0.195090324f, -0.923879504f, 0.555570245f, 0.707106769f, -0.831469595f, -0.382683426f, 0.980785251f}, {1f, -0.555570245f, -0.382683426f, 0.980785251f, -0.707106769f, -0.195090324f, 0.923879504f, -0.831469595f}, {1f, -0.831469595f, 0.382683426f, 0.195090324f, -0.707106769f, 0.980785251f, -0.923879504f, 0.555570245f}, {1f, -0.980785251f, 0.923879504f, -0.831469595f, 0.707106769f, -0.555570245f, 0.382683426f, -0.195090324f}, }; Assert.AreEqual(ExpectedCosCoef, CosCoef); }
public override void Initialize() { base.Initialize(); customProjectPackage = new CustomProjectPackage(); ((IVsPackage)customProjectPackage).SetSite(serviceProvider); customProjectFactory = new MyCustomProjectFactory(customProjectPackage); base.SetMsbuildEngine(customProjectFactory); int canCreate; if(VSConstants.S_OK == ((IVsProjectFactory)customProjectFactory).CanCreateProject(projectFile, (uint)__VSCREATEPROJFLAGS.CPF_OPENFILE, out canCreate)) { PrivateType type = new PrivateType(typeof(MyCustomProjectFactory)); PrivateObject obj = new PrivateObject(customProjectFactory, type); projectNode = (MyCustomProjectNode)obj.Invoke("PreCreateForOuter", new object[] { IntPtr.Zero }); Guid iidProject = new Guid(); int pfCanceled; projectNode.Load(projectFile, "", "", (uint)__VSCREATEPROJFLAGS.CPF_OPENFILE, ref iidProject, out pfCanceled); } }
public void Setup() { voxelClusterHandlerType = new PrivateType(typeof(VoxelClusterHandler)); }
public void VCCV_English_test() { Console.WriteLine("STARTING VCCV ENGLISH GetConnectingNotes TEST"); // reflection to test private stuff var parent_type = typeof(VCCV_English); var inner_type = parent_type.GetNestedType("VCCV_English_Syllable", BindingFlags.NonPublic); PrivateType inner_type_private = new PrivateType(inner_type); //1 var input_note = new UtauNote(new string[] { "[#0010]", "Length=229", "Lyric=fIn", "NoteNum=50" }); var next_note = new UtauNote(new string[] { "[#0011]", "Length=240", "Lyric=R", "NoteNum=46" }); var result = VCCV_English.GetConnectingNotes(null, input_note, next_note); var expected = new List <UtauNote>(new UtauNote[] { new UtauNote(new string[] { "[#0010]", "Length=169", "Lyric=-fI", "NoteNum=50", }), new UtauNote(new string[] { "[#0010]", "Length=60", "Lyric=In-", "NoteNum=50", }), }); CollectionAssert.AreEqual(expected.ConvertAll <string>(x => x.ToString()), result.ConvertAll <string>(x => x.ToString())); //2 input_note = new UtauNote(new string[] { "[#0010]", "Length=229", "Lyric=fIn", "NoteNum=50" }); next_note = new UtauNote(new string[] { "[#0011]", "Length=240", "Lyric=dhen", "NoteNum=46" }); result = VCCV_English.GetConnectingNotes(null, input_note, next_note); expected = new List <UtauNote>(new UtauNote[] { new UtauNote(new string[] { "[#0010]", "Length=109", "Lyric=-fI", "NoteNum=50", }), new UtauNote(new string[] { "[#0010]", "Length=60", "Lyric=In-", "NoteNum=50", }), new UtauNote(new string[] { "[#0010]", "Length=60", "Lyric=n dh", "NoteNum=50", }), }); CollectionAssert.AreEqual(expected.ConvertAll <string>(x => x.ToString()), result.ConvertAll <string>(x => x.ToString())); Console.WriteLine("ENDING VCCV ENGLISH GetConnectingNotes TEST"); }
public void SavePng_BuildInProgress() { { // MachineInfo is in the picture, so make MachineInfo as machine indepenent string for unit test puroposes string machineIndepenentInfo = "Processors: 1 | Cores: 2 | CPU Speed: 2.7GHz | Hyper Threading: Enabled | RAM: 8GB | HDD: 1 SSD"; MachineInfo mi = MachineInfo.Instance; var machineInfo = new PrivateObject(mi); // Use PrivateObject class to change private member of MachineInfo object. machineInfo.SetField("info", machineIndepenentInfo); Assert.AreEqual(MachineInfo.Instance.ToString(), machineIndepenentInfo); // Verify if internal data were updated } { // Feed DataModel with sample data DataModel dm = DataModel.Instance; var dataModel = new PrivateObject(dm); // Use PrivateObject class to change private member of MachineInfo object. dataModel.SetProperty("SolutionName", "Example.sln"); dataModel.SetProperty("StartTime", new System.DateTime(636848298660196710L)); dataModel.SetProperty("MaxParallelBuilds", 4); //<c>string</c> is ProjectUniqueName, <c>uint</c> is project build order number, <c>long</c> is project Start time, relative, counted since <c>DataModel.StartTime</c> in <c>DateTime.Ticks</c> units. Dictionary <string, Tuple <uint, long> > currentBuilds = new Dictionary <string, Tuple <uint, long> > { { "WpfToolTip\\WpfToolTip.csproj", new Tuple <uint, long>(2, 77409902) }, { "constexpr_templates\\constexpr_templates.vcxproj", new Tuple <uint, long>(3, 79745101) }, { "DiskPerformance\\DiskPerformance.csproj", new Tuple <uint, long>(4, 81644812) }, { "junk-vector-const\\junk-vector-const.vcxproj", new Tuple <uint, long>(5, 83574518) }, }; dataModel.SetField("currentBuilds", currentBuilds); List <BuildInfo> finishedBuilds = new List <BuildInfo>() { new BuildInfo("junk-finddir\\junk-finddir.vcxproj", "junk-finddir.vcxproj", 1, 359937, 77299946, true) }; dataModel.SetField("finishedBuilds", finishedBuilds); Dictionary <string, List <string> > projectDependenies = new Dictionary <string, List <string> >(); //<c>string</c> is ProjectUniqueName, <c>List<string></c> is list of projects that <c>Key</c> project depends on dataModel.SetField("projectDependenies", projectDependenies); List <BuildInfo> criticalPath = new List <BuildInfo>(); dataModel.SetField("criticalPath", criticalPath); List <Tuple <long, float> > cpuUsage = new List <Tuple <long, float> >() { new Tuple <long, float>(636848298660196710, 0.0f), new Tuple <long, float>(636848298670348211, 77.42183f), new Tuple <long, float>(636848298681079693, 58.4654f), new Tuple <long, float>(636848298691089400, 78.53645f), new Tuple <long, float>(636848298701193247, 43.16831f), new Tuple <long, float>(636848298711194104, 40.23949f), new Tuple <long, float>(636848298721322554, 33.27891f), new Tuple <long, float>(636848298731336449, 37.58672f), new Tuple <long, float>(636848298741491580, 43.4553f), new Tuple <long, float>(636848298752339901, 94.59882f) }; dataModel.SetField("cpuUsage", cpuUsage); List <Tuple <long, float> > hddUsage = new List <Tuple <long, float> >() { new Tuple <long, float>(636848298660196710, 0.0f), new Tuple <long, float>(636848298670348211, 3.894294f), new Tuple <long, float>(636848298681079693, 10.60813f), new Tuple <long, float>(636848298691089400, 37.33977f), new Tuple <long, float>(636848298701193247, 3.864434f), new Tuple <long, float>(636848298711194104, 4.997182f), new Tuple <long, float>(636848298721322554, 3.919567f), new Tuple <long, float>(636848298731336449, 9.422446f), new Tuple <long, float>(636848298741491580, 5.652133f), new Tuple <long, float>(636848298752339901, 0.8484202f) }; dataModel.SetField("hddUsage", hddUsage); { // private static need to be handled through PrivateType PrivateType pt = new PrivateType(typeof(DataModel)); pt.SetStaticFieldOrProperty("projectBuildOrderNumber", 5u); } Assert.AreEqual(DataModel.Instance.SolutionName, "Example.sln"); // Verify if internal data were updated } PBMControl pBMcontrol = new PBMControl(); var graphControl = new PrivateObject(GraphControl.Instance); // Use PrivateObject class to change private member of GraphControl object. graphControl.SetField("nowTickForTest", 636848298760000000L); Window window = new Window { Width = 800, Height = 600, Content = pBMcontrol }; window.Show(); //this will draw PBMControl //window.ShowDialog(); //for debug string expected = TestUtils.GetTestFile("BuildInProgress.png"); // ResultsDirectory <= this is where results should be saved. How to get value of this xaml tag? string tmpFileName = Path.GetTempFileName(); //this method return path to non-existing file in temp directory tmpFileName += ".png"; bool res = pBMcontrol.SaveGraph(tmpFileName /*pathToPngFile*/); Assert.IsTrue(res); Assert.IsTrue(ImageComparer.AreImagesEqual(expected, tmpFileName)); }
public void TestWithInvalidDate() { PrivateType pObj = new PrivateType(typeof(GRMApplication.Program)); DateTime expectedDate = (DateTime)pObj.InvokeStatic("ParseDate", "43rd Irrelivembruary 2017"); }
private static string CalculateV2Key(PrivateType accessor, byte[] keySalt) { object[] parameters = new object[] { MASTERPASSWORD, keySalt }; return(accessor.InvokeStatic("CalculateMasterPasswordKey", parameters).ToString()); }
public void Initialize() { shimsContext = ShimsContext.Create(); SetupShims(); privateType = new PrivateType(typeof(Notification)); }
public void GetCellValue_ParamsNull_ReturnNull() { var priType = new PrivateType(typeof(ExcelExtensions)); Assert.IsNull(priType.InvokeStatic("GetValue", BindingFlags.NonPublic, (Cell)null, (WorkbookPart)null)); }
protected void ResetOperationId() { var acc = new PrivateType(typeof(SnTrace.Operation)); acc.SetStaticField("_nextId", 1L); }
public void Initialize() { _privateType = new PrivateType(typeof(KQL)); }
public void Setup() { _context = ShimsContext.Create(); _reporting = new ApiReporting(); _privateType = new PrivateType(typeof(ApiReporting)); }
private static bool TestIsLowLevelSupportedBase(string source) { var @class = new PrivateType(typeof(MonitorConfiguration)); return((bool)@class.InvokeStatic("IsLowLevelSupported", source)); }
public void MyTestInitialize() { PrivateType instanceForm = new PrivateType(typeof(InvisibleForm)); instanceForm.SetStaticFieldOrProperty("instanceForm", null); }
public void User_IdentityChangesWhenNewHostAdded_IdentityChangesAreCorrect() { // Clear the KnownHostSet. PrivateType privateKnownHostSet = new PrivateType(typeof(KnownHostSet)); PrivateObject privateInstance = new PrivateObject(privateKnownHostSet.GetStaticProperty("Instance", null)); ((HashSet <string>)privateInstance.GetField("knownHosts")).Clear(); UtilityProgram.Instance.Executable = new FileInfo("MockUtil.exe"); License testLicense = new License() { Port = 27001, Host = "LmStatTest" }; // Using GetStatusAsync may be overkill for testing the property changes, but it // throws in some threading. using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { testLicense.GetStatusCompleted += (s, e) => waitHandle.Set(); testLicense.GetStatusAsync(); if (!waitHandle.WaitOne(5100, false)) { Assert.Fail("Test timed out."); } } Feature testFeature = testLicense.Features.First(f => f.Name == "Users_With_Spaces_ChangedEvent_Other"); User target = testFeature.Users.First(); Assert.AreEqual(target.Name, "user 504 CAD9695D", "Name property."); Assert.AreEqual(target.Host, "display", "Host property."); Assert.AreEqual(target.Display, "A504", "Display property."); List <string> propertiesChanged = new List <string>(); target.PropertyChanged += (s, e) => propertiesChanged.Add(e.PropertyName); License nxLicense = new License() { Port = 27000, Host = "LmStatNX" }; using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { nxLicense.GetStatusCompleted += (s, e) => waitHandle.Set(); nxLicense.GetStatusAsync(); if (!waitHandle.WaitOne(5100, false)) { Assert.Fail("Test timed out."); } } Assert.IsTrue(propertiesChanged.Contains("Name")); Assert.IsTrue(propertiesChanged.Contains("Host")); Assert.IsTrue(propertiesChanged.Contains("Display")); Assert.AreEqual(target.Name, "user 504", "Name property."); Assert.AreEqual(target.Host, "CAD9695D", "Host property."); Assert.AreEqual(target.Display, "display A504", "Display property."); }
public void Initialize() { _target = new PrivateType(typeof(InputInspectorTypeHelper)); }
public void Initialize() { _target = new PrivateType(typeof(DataBaseManager)); }
public void Cleanup() { _privateType = null; }
private string TestGetDeviceInstanceIdBase(string source) { var @class = new PrivateType(typeof(DeviceContext)); return((string)@class.InvokeStatic("GetDeviceInstanceId", source)); }
public void TestBodies() { string jsonString = System.IO.File.ReadAllText("edsmBodies.json"); JObject response = JsonConvert.DeserializeObject <JObject>(jsonString); PrivateType starMapService = new PrivateType(typeof(StarMapService)); List <Body> bodies = (List <Body>)starMapService.InvokeStatic("ParseStarMapBodies", new object[] { response }); Assert.IsNotNull(bodies); // Test our main star and belt Body star = bodies.Find(s => s.bodyname == "Shinrarta Dezhra"); Assert.AreEqual("Shinrarta Dezhra", star.shortname); Assert.AreEqual(14923, star.EDSMID); Assert.AreEqual("Star", star.bodyType.invariantName); Assert.AreEqual("K", star.stellarclass); Assert.AreEqual("Shinrarta Dezhra", star.systemname); Assert.AreEqual(0, star.distance); Assert.IsTrue((bool)star.mainstar); Assert.AreEqual(8068, star.age); Assert.AreEqual("V", star.luminosityclass); Assert.AreEqual(7.129517, (double)star.absolutemagnitude, 0.01); Assert.AreEqual(0.648438, (double)star.solarmass, 0.01); Assert.AreEqual(0.7666015240833932, (double)star.solarradius, 0.01); Assert.AreEqual(4343, (double)star.temperature, 0.01); Assert.AreEqual(1847.1559259259259, (double)star.orbitalperiod, 0.01); Assert.AreEqual(577.32870032374433, (double)star.semimajoraxis, 0.01); Assert.AreEqual(0.018651, (double)star.eccentricity, 0.01); Assert.AreEqual(21.11883, (double)star.inclination, 0.01); Assert.AreEqual(201.271866, (double)star.periapsis, 0.01); Assert.AreEqual(3.3057685908564816, (double)star.rotationalperiod, 0.01); Assert.AreEqual(false, star.tidallylocked); Assert.AreEqual(-0.041915, (double)star.tilt, 0.01); Assert.AreEqual(1, star.rings?.Count); Assert.AreEqual("Rocky", star.rings[0].invariantComposition); Assert.AreEqual(1522275140, star.updatedat); Assert.IsNull(star.scanned); Assert.IsNull(star.mapped); // Test value estimation Assert.AreEqual(0, star.estimatedvalue); star.scanned = System.DateTime.UtcNow; Assert.AreEqual(1212, star.estimatedvalue); // Test landable high metal content world Body body = bodies.Find(s => s.bodyname == "Shinrarta Dezhra A 1"); Assert.AreEqual("A 1", body.shortname); Assert.AreEqual(7058, body.EDSMID); Assert.AreEqual("Planet", body.bodyType.invariantName); Assert.AreEqual("High metal content world", body.planetClass.invariantName); Assert.AreEqual(40.472694, (double)body.distance, 0.01); Assert.IsTrue((bool)body.landable); Assert.AreEqual(0.9955175545631726, (double)body.gravity, 0.01); Assert.AreEqual(0.777331, (double)body.earthmass, 0.01); Assert.AreEqual(5635.897, (double)body.radius, 0.01); Assert.AreEqual(581, body.temperature); Assert.IsNull(body.pressure); Assert.IsNull(body.volcanism); Assert.AreEqual("No atmosphere", body.atmosphereclass.invariantName); Assert.AreEqual(0, body.atmospherecompositions.Count); Assert.AreEqual("Rock", body.solidcompositions[0].invariantName); Assert.AreEqual(66.83109999999999, (double)body.solidcompositions[0].percent, 0.01); Assert.AreEqual("Metal", body.solidcompositions[1].invariantName); Assert.AreEqual(33.1689, (double)body.solidcompositions[1].percent, 0.01); Assert.AreEqual("Not terraformable", body.terraformState.invariantName); Assert.AreEqual(10.463153935185185, (double)body.orbitalperiod, 0.01); Assert.AreEqual(40.439289663517812, (double)body.semimajoraxis, 0.01); Assert.AreEqual(0.002692, (double)body.eccentricity, 0.01); Assert.AreEqual(-0.044359, (double)body.inclination, 0.01); Assert.AreEqual(115.330589, (double)body.periapsis, 0.01); Assert.AreEqual(10.341365740740741, (double)body.rotationalperiod, 0.01); Assert.IsTrue((bool)body.tidallylocked); Assert.AreEqual(0.271899, (double)body.tilt, 0.01); Assert.AreEqual(11, body.materials.Count); Assert.AreEqual("Manganese", body.materials[4].name); Assert.AreEqual(9.57628, (double)body.materials[4].percentage, 0.01); Assert.AreEqual("Arsenic", body.materials[7].name); Assert.AreEqual(2.16406, (double)body.materials[7].percentage, 0.01); Assert.AreEqual(1539922044, body.updatedat); Assert.IsNull(body.scanned); Assert.IsNull(body.mapped); // Test value estimation Assert.AreEqual(0, body.estimatedvalue); body.scanned = System.DateTime.UtcNow; Assert.AreEqual(14849, body.estimatedvalue); body.mapped = System.DateTime.UtcNow; Assert.AreEqual(49497, body.estimatedvalue); // Test terraformed body body = bodies.Find(s => s.bodyname == "Founders World"); Assert.AreEqual("Founders World", body.shortname); Assert.AreEqual(12765, body.EDSMID); Assert.AreEqual("Planet", body.bodyType.invariantName); Assert.AreEqual("Earth-like world", body.planetClass.invariantName); Assert.AreEqual(324.465424, (double)body.distance, 0.01); Assert.AreEqual(false, body.landable); Assert.AreEqual(0.9327034079798093, (double)body.gravity, 0.01); Assert.AreEqual(0.69, (double)body.earthmass, 0.01); Assert.AreEqual(5485.766, (double)body.radius, 0.01); Assert.AreEqual(298, body.temperature); Assert.AreEqual(2.3013969590426844, (double)body.pressure, 0.01); Assert.IsNull(body.volcanism); Assert.AreEqual("Suitable for water-based life", body.atmosphereclass.invariantName); Assert.AreEqual(2, body.atmospherecompositions.Count); Assert.AreEqual("Nitrogen", body.atmospherecompositions[0].invariantName); Assert.AreEqual(91.2489, (double)body.atmospherecompositions[0].percent, 0.01); Assert.AreEqual("Oxygen", body.atmospherecompositions[1].invariantName); Assert.AreEqual(8.69037, (double)body.atmospherecompositions[1].percent, 0.01); Assert.AreEqual("Rock", body.solidcompositions[0].invariantName); Assert.AreEqual(70, (double)body.solidcompositions[0].percent, 0.01); Assert.AreEqual("Metal", body.solidcompositions[1].invariantName); Assert.AreEqual(30, (double)body.solidcompositions[1].percent, 0.01); Assert.AreEqual("Terraformed", body.terraformState.invariantName); Assert.AreEqual(248.72930555555556, (double)body.orbitalperiod, 0.01); Assert.AreEqual(334.33343980921632, (double)body.semimajoraxis, 0.01); Assert.AreEqual(0.034386, (double)body.eccentricity, 0.01); Assert.AreEqual(8.552103, (double)body.inclination, 0.01); Assert.AreEqual(183.237366, (double)body.periapsis, 0.01); Assert.AreEqual(41.96157696759259, (double)body.rotationalperiod, 0.01); Assert.AreEqual(false, body.tidallylocked); Assert.AreEqual(0.373026, (double)body.tilt, 0.01); Assert.AreEqual(0, body.materials.Count); Assert.AreEqual(1539922044, body.updatedat); Assert.IsNull(body.scanned); Assert.IsNull(body.mapped); // Test value estimation Assert.AreEqual(0, body.estimatedvalue); body.scanned = System.DateTime.UtcNow; Assert.AreEqual(276297, body.estimatedvalue); body.mapped = System.DateTime.UtcNow; Assert.AreEqual(920990, body.estimatedvalue); // Test volcanic icy body body = bodies.Find(s => s.bodyname == "Shinrarta Dezhra AB 1 b"); Assert.AreEqual("AB 1 b", body.shortname); Assert.AreEqual(8138660, body.EDSMID); Assert.AreEqual("Moon", body.bodyType.invariantName); Assert.AreEqual("Icy body", body.planetClass.invariantName); Assert.AreEqual(3250.803223, (double)body.distance, 0.01); Assert.AreEqual(false, body.landable); Assert.AreEqual(0.08637144960988087, (double)body.gravity, 0.01); Assert.AreEqual(0.004357, (double)body.earthmass, 0.01); Assert.AreEqual(1432.49525, (double)body.radius, 0.01); Assert.AreEqual(124, body.temperature); Assert.AreEqual(0.3520057673328399, (double)body.pressure, 0.01); Assert.IsNotNull(body.volcanism); Assert.AreEqual("Minor", body.volcanism.invariantAmount); Assert.AreEqual("Nitrogen", body.volcanism.invariantComposition); Assert.AreEqual("Magma", body.volcanism.invariantType); Assert.AreEqual("Methane", body.atmosphereclass.invariantName); Assert.AreEqual(1, body.atmospherecompositions.Count); Assert.AreEqual("Ice", body.solidcompositions[0].invariantName); Assert.AreEqual(81.6586, (double)body.solidcompositions[0].percent, 0.01); Assert.AreEqual("Rock", body.solidcompositions[1].invariantName); Assert.AreEqual(16.653200000000002, (double)body.solidcompositions[1].percent, 0.01); Assert.AreEqual("Metal", body.solidcompositions[2].invariantName); Assert.AreEqual(1.6882000000000001, (double)body.solidcompositions[2].percent, 0.01); Assert.AreEqual("Not terraformable", body.terraformState.invariantName); Assert.AreEqual(7.854005353009259, (double)body.orbitalperiod, 0.01); Assert.AreEqual(4.9088274262056295, (double)body.semimajoraxis, 0.01); Assert.AreEqual(0.000164, (double)body.eccentricity, 0.01); Assert.AreEqual(0.025755, (double)body.inclination, 0.01); Assert.AreEqual(300.792816, (double)body.periapsis, 0.01); Assert.AreEqual(7.854289641203704, (double)body.rotationalperiod, 0.01); Assert.IsTrue((bool)body.tidallylocked); Assert.AreEqual(-0.287234, (double)body.tilt, 0.01); Assert.AreEqual(0, body.materials.Count); Assert.AreEqual(1539922044, body.updatedat); Assert.IsNull(body.scanned); Assert.IsNull(body.mapped); // Test value estimation Assert.AreEqual(0, body.estimatedvalue); body.scanned = System.DateTime.UtcNow; Assert.AreEqual(500, body.estimatedvalue); body.mapped = System.DateTime.UtcNow; Assert.AreEqual(1191, body.estimatedvalue); // Test ringed gas giant body = bodies.Find(s => s.bodyname == "Shinrarta Dezhra AB 2"); Assert.AreEqual("AB 2", body.shortname); Assert.AreEqual(8138626, body.EDSMID); Assert.AreEqual("Planet", body.bodyType.invariantName); Assert.AreEqual("Class I gas giant", body.planetClass.invariantName); Assert.AreEqual(3767.557861, (double)body.distance, 0.01); Assert.AreEqual(false, body.landable); Assert.AreEqual(3.8552143758323023, (double)body.gravity, 0.01); Assert.AreEqual(484.303284, (double)body.earthmass, 0.01); Assert.AreEqual(71485.664, (double)body.radius, 0.01); Assert.AreEqual(123, body.temperature); Assert.IsNull(body.pressure); Assert.IsNull(body.volcanism); Assert.AreEqual("Gas giant", body.atmosphereclass.invariantName); Assert.AreEqual(2, body.atmospherecompositions.Count); Assert.AreEqual("Hydrogen", body.atmospherecompositions[0].invariantName); Assert.AreEqual(72.8469, (double)body.atmospherecompositions[0].percent, 0.01); Assert.AreEqual("Helium", body.atmospherecompositions[1].invariantName); Assert.AreEqual(27.1531, (double)body.atmospherecompositions[1].percent, 0.01); Assert.AreEqual(0, body.solidcompositions.Count); Assert.AreEqual("Not terraformable", body.terraformState.invariantName); Assert.AreEqual(7354.8133333333335, (double)body.orbitalperiod, 0.01); Assert.AreEqual(3765.2874442358393, (double)body.semimajoraxis, 0.01); Assert.AreEqual(0.007439, (double)body.eccentricity, 0.01); Assert.AreEqual(-0.406597, (double)body.inclination, 0.01); Assert.AreEqual(305.503632, (double)body.periapsis, 0.01); Assert.AreEqual(1.1907941804166666, (double)body.rotationalperiod, 0.01); Assert.AreEqual(false, body.tidallylocked); Assert.AreEqual(0.868699, (double)body.tilt, 0.01); Assert.AreEqual(0, body.materials.Count); Assert.IsNotNull(body.rings); Assert.AreEqual(1, body.rings.Count); Assert.AreEqual("Shinrarta Dezhra AB 2 A Ring", body.rings[0].name); Assert.AreEqual("Icy", body.rings[0].invariantComposition); Assert.AreEqual(239990000000, body.rings[0].mass); Assert.AreEqual(130900, body.rings[0].innerradius); Assert.AreEqual(273390, body.rings[0].outerradius); Assert.AreEqual("Common", body.reserveLevel.invariantName); Assert.AreEqual(1539922044, body.updatedat); Assert.IsNull(body.scanned); Assert.IsNull(body.mapped); // Test value estimation Assert.AreEqual(0, body.estimatedvalue); body.scanned = System.DateTime.UtcNow; Assert.AreEqual(4883, body.estimatedvalue); body.mapped = System.DateTime.UtcNow; Assert.AreEqual(16278, body.estimatedvalue); }
public void VCCV_English_Syllable_test() { Console.WriteLine("STARTING VCCV ENGLISH SYLLABLE TEST"); // reflection to test private stuff var parent_type = typeof(VCCV_English); var inner_type = parent_type.GetNestedType("VCCV_English_Syllable", BindingFlags.NonPublic); PrivateType inner_type_private = new PrivateType(inner_type); //1 var result = inner_type_private.InvokeStatic("SplitSyllable", BindingFlags.NonPublic, "lak"); var expected = new PrivateObject(Activator.CreateInstance(inner_type, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { "l", "a", "k" }, null, null)); Assert.AreEqual <string>((string)expected.Invoke("ToString"), result.ToString()); //2 result = inner_type_private.InvokeStatic("SplitSyllable", BindingFlags.NonPublic, "la"); expected = new PrivateObject(Activator.CreateInstance(inner_type, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { new List <string> { "l" }, new List <string> { "a" }, new List <string> { } }, null, null)); Assert.AreEqual <string>((string)expected.Invoke("ToString"), result.ToString()); //3 result = inner_type_private.InvokeStatic("SplitSyllable", BindingFlags.NonPublic, "ak"); expected = new PrivateObject(Activator.CreateInstance(inner_type, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { new List <string> { }, new List <string> { "a" }, new List <string> { "k" } }, null, null)); Assert.AreEqual <string>((string)expected.Invoke("ToString"), result.ToString()); //4 result = inner_type_private.InvokeStatic("SplitSyllable", BindingFlags.NonPublic, "stak"); expected = new PrivateObject(Activator.CreateInstance(inner_type, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { "st", "a", "k" }, null, null)); Assert.AreEqual <string>((string)expected.Invoke("ToString"), result.ToString()); //5 /*result = inner_type_private.InvokeStatic("SplitSyllable", BindingFlags.NonPublic, "b6lbz"); * expected = new PrivateObject(Activator.CreateInstance(inner_type, BindingFlags.Instance | BindingFlags.NonPublic, null, * new object[] { * new List<string> { "b" } , * new List<string> { "6" } , * new List<string> { "l", "bz" } * }, * null, null)); * Assert.AreEqual<string>((string)expected.Invoke("ToString"), result.ToString());*/ //6 result = inner_type_private.InvokeStatic("SplitSyllable", BindingFlags.NonPublic, "str1ng"); expected = new PrivateObject(Activator.CreateInstance(inner_type, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { "str", "1", "ng" }, null, null)); Assert.AreEqual <string>((string)expected.Invoke("ToString"), result.ToString()); //7 result = inner_type_private.InvokeStatic("SplitSyllable", BindingFlags.NonPublic, "pyongz"); expected = new PrivateObject(Activator.CreateInstance(inner_type, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { "py", "o", "ngz" }, null, null)); Assert.AreEqual <string>((string)expected.Invoke("ToString"), result.ToString()); Console.WriteLine("ENDING VCCV ENGLISH SYLLABLE TEST"); }
public void TestStations() { // Test stations data string jsonString = System.IO.File.ReadAllText("edsmStations.json"); JObject response = JsonConvert.DeserializeObject <JObject>(jsonString); PrivateType starMapService = new PrivateType(typeof(StarMapService)); List <Station> stations = (List <Station>)starMapService.InvokeStatic("ParseStarMapStations", new object[] { response }); Assert.IsNotNull(stations); // Test Jameson Memorial Station station = stations.Find(s => s.name == "Jameson Memorial"); Assert.AreEqual(65, station.EDSMID); Assert.AreEqual(128666762, station.marketId); Assert.AreEqual("Orbis Starport", station.Model.invariantName); Assert.AreEqual(324.925354M, station.distancefromstar); Assert.AreEqual("Pilots Federation", station.Faction.Allegiance.invariantName); Assert.AreEqual("Democracy", station.Faction.Government.invariantName); Assert.AreEqual("Pilots Federation Local Branch", station.Faction.name); Assert.AreEqual(80576, station.Faction.EDSMID); Assert.AreEqual(2, station.economies.Count); Assert.AreEqual("High Tech", station.economies[0]); Assert.AreEqual("Industrial", station.economies[1]); Assert.IsTrue((bool)station.hasmarket); Assert.IsTrue((bool)station.hasshipyard); Assert.IsTrue((bool)station.hasoutfitting); Assert.IsTrue((bool)station.hasdocking); Assert.IsTrue((bool)station.hasrearm); Assert.IsTrue((bool)station.hasrefuel); Assert.IsTrue((bool)station.hasrepair); Assert.IsTrue(station.stationServices.Exists(s => s.invariantName == "Commodities")); Assert.IsTrue(station.stationServices.Exists(s => s.invariantName == "Technology Broker")); Assert.AreEqual(1540189980, station.updatedat); Assert.AreEqual(1540189980, station.shipyardupdatedat); Assert.AreEqual(1540189980, station.commoditiesupdatedat); Assert.AreEqual(1540189980, station.outfittingupdatedat); // Test Jameson Base (Engineer's workshop) station = stations.Find(s => s.name == "Jameson Base"); Assert.AreEqual(285, station.EDSMID); Assert.AreEqual(128679815, station.marketId); Assert.AreEqual("Surface Station", station.Model.invariantName); Assert.AreEqual(40.333652M, station.distancefromstar); Assert.AreEqual("Independent", station.Faction.Allegiance.invariantName); Assert.AreEqual("Engineer", station.Faction.Government.invariantName); Assert.AreEqual("Lori Jameson", station.Faction.name); Assert.IsNull(station.Faction.EDSMID); Assert.AreEqual(2, station.economies.Count); Assert.AreEqual("Colony", station.economies[0]); Assert.AreEqual("None", station.economies[1]); Assert.AreEqual(false, station.hasmarket); Assert.AreEqual(false, station.hasshipyard); Assert.IsTrue((bool)station.hasoutfitting); Assert.IsTrue((bool)station.hasdocking); Assert.IsTrue((bool)station.hasrearm); Assert.IsTrue((bool)station.hasrefuel); Assert.IsTrue((bool)station.hasrepair); Assert.IsTrue(station.stationServices.Exists(s => s.invariantName == "Contacts")); Assert.AreEqual(1540179943, station.updatedat); Assert.AreEqual(null, station.shipyardupdatedat); Assert.AreEqual(null, station.commoditiesupdatedat); Assert.AreEqual(1540179943, station.outfittingupdatedat); }
public void TestWithEmptyDate() { PrivateType pObj = new PrivateType(typeof(GRMApplication.Program)); DateTime expectedDate = (DateTime)pObj.InvokeStatic("ParseDate", ""); }
public void Aspect_OData_AddRemoveFields() { var aspect = Content.CreateNew("Aspect", Repository.AspectsFolder, Guid.NewGuid().ToString()); aspect.Save(); //var aspectPath = aspect.Path; var resourcePath = ODataHandler.GetEntityUrl(aspect.Path); var content = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString()); content.AddAspects(aspect.Path); content.Save(); var odataHandlerAcc = new PrivateType(typeof(ODataHandler)); var originalActionResolver = odataHandlerAcc.GetStaticProperty("ActionResolver"); odataHandlerAcc.SetStaticProperty("ActionResolver", new ODataTests.TestActionResolver()); var fieldInfosJson = GetJson(new[] { new FieldInfo { Name = "Field1", Type = "ShortText" }, new FieldInfo { Name = "Field2", Type = "ShortText" }, new FieldInfo { Name = "Field3", Type = "ShortText" }, }); ODataTests.CreateTestSite(); try { string result; Field field; using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/AddFields"), "", output); var handler = new ODataHandler(); var stream = ODataTests.CreateRequestStream(String.Concat("{fields:", fieldInfosJson, "}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field1", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field2", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field3", out field)); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field4", out field)); fieldInfosJson = GetJson(new[] { new FieldInfo { Name = "Field4", Type = "ShortText" }, }); using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/AddFields"), "", output); var handler = new ODataHandler(); var stream = ODataTests.CreateRequestStream(String.Concat("{fields:", fieldInfosJson, "}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field1", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field2", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field3", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field4", out field)); using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveFields"), "", output); var handler = new ODataHandler(); var stream = ODataTests.CreateRequestStream(String.Concat("{fields:[\"Field1\"]}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field1", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field2", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field3", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field4", out field)); using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveFields"), "", output); var handler = new ODataHandler(); var stream = ODataTests.CreateRequestStream(String.Concat("{fields:[\"Field4\",\"Field2\"]}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field1", out field)); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field2", out field)); Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field3", out field)); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field4", out field)); using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveAllFields"), "", output); var handler = new ODataHandler(); handler.ProcessRequest(pc.OwnerHttpContext, "POST", null); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field1", out field)); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field2", out field)); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field3", out field)); Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field4", out field)); } finally { odataHandlerAcc.SetStaticProperty("ActionResolver", originalActionResolver); content.DeletePhysical(); ODataTests.CleanupTestSite(); } }
public void UpdateTestWithStepValues_Sets_The_Correct_FailureMessage() { //------------Setup for test------------------------- var resourceId = Guid.NewGuid(); const string Datalist = "<DataList><scalar1 ColumnIODirection=\"Input\"/><persistantscalar ColumnIODirection=\"Input\"/><rs><f1 ColumnIODirection=\"Input\"/><f2 ColumnIODirection=\"Input\"/></rs><recset><field1/><field2/></recset></DataList>"; var serviceAction = new ServiceAction { DataListSpecification = new StringBuilder(Datalist), Service = new DynamicService { ID = resourceId } }; var dsfObj = new Mock <IDSFDataObject>(); dsfObj.SetupProperty(o => o.ResourceID); const string TestName = "test1"; dsfObj.Setup(o => o.TestName).Returns(TestName); dsfObj.Setup(o => o.StopExecution).Returns(true); dsfObj.Setup(o => o.Environment).Returns(new ExecutionEnvironment()); dsfObj.Setup(o => o.Environment.Eval(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <bool>(), false)) .Returns(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.NewDataString("Args"))); dsfObj.Setup(o => o.Environment.AllErrors).Returns(new HashSet <string>()); dsfObj.Setup(o => o.IsDebugMode()).Returns(true); dsfObj.Setup(o => o.Environment.HasErrors()).Returns(true); dsfObj.Setup(o => o.Environment.FetchErrors()).Returns("Failed: The user running the test is not authorized to execute resource ."); var fetch = JsonResource.Fetch("UnAuthorizedHelloWorld"); var s = new Dev2JsonSerializer(); var testModelTO = s.Deserialize <ServiceTestModelTO>(fetch); var cataLog = new Mock <ITestCatalog>(); cataLog.Setup(cat => cat.SaveTest(It.IsAny <Guid>(), It.IsAny <IServiceTestModelTO>())).Verifiable(); cataLog.Setup(cat => cat.FetchTest(resourceId, TestName)).Returns(testModelTO); var resourceCat = new Mock <IResourceCatalog>(); var activity = new Mock <IDev2Activity>(); resourceCat.Setup(catalog => catalog.Parse(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(activity.Object); var workSpace = new Mock <IWorkspace>(); var channel = new Mock <IEsbChannel>(); var esbExecuteRequest = new EsbExecuteRequest(); var serviceTestExecutionContainer = new ServiceTestExecutionContainer(serviceAction, dsfObj.Object, workSpace.Object, channel.Object, esbExecuteRequest); var testObj = new PrivateType(serviceTestExecutionContainer.GetType()); var test = SetupServiceTestSteps(); testObj.InvokeStatic("UpdateTestWithStepValues", test.Object); //------------Execute Test--------------------------- var expectedMessage = @"Failed Step: Message: Test Failed because of some reasons Failed Output For Variable: Message: This test has failed Invalid Output for Variable: Message: This test is invalid Pending Output for Variable: Test Failed because of some reasons "; //------------Assert Results------------------------- test.VerifySet(to => { to.FailureMessage = expectedMessage.ToString(); }, Times.AtLeastOnce); }
public void Aspect_OData_AddRemoveAspect() { var content = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString()); content.Save(); var resourcePath = ODataHandler.GetEntityUrl(content.Path); var aspect1 = Content.CreateNew("Aspect", Repository.AspectsFolder, Guid.NewGuid().ToString()); aspect1.Save(); var aspect1Path = aspect1.Path; var aspect2 = Content.CreateNew("Aspect", Repository.AspectsFolder, Guid.NewGuid().ToString()); aspect2.Save(); var aspect2Path = aspect2.Path; var aspect3 = Content.CreateNew("Aspect", Repository.AspectsFolder, Guid.NewGuid().ToString()); aspect3.Save(); var aspect3Path = aspect3.Path; var odataHandlerAcc = new PrivateType(typeof(ODataHandler)); var originalActionResolver = odataHandlerAcc.GetStaticProperty("ActionResolver"); odataHandlerAcc.SetStaticProperty("ActionResolver", new ODataTests.TestActionResolver()); ODataTests.CreateTestSite(); try { string result; using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/AddAspects"), "", output); var handler = new ODataHandler(); var stream = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect1Path, "\"]}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler)); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler)); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler)); using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/AddAspects"), "", output); var handler = new ODataHandler(); var stream = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect2Path, "\", \"", aspect3Path, "\"]}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler)); Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler)); Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler)); using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveAspects"), "", output); var handler = new ODataHandler(); var stream = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect1Path, "\", \"", aspect3Path, "\"]}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler)); Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler)); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler)); using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveAspects"), "", output); var handler = new ODataHandler(); var stream = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect2Path, "\"]}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler)); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler)); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler)); content.AddAspects((Aspect)aspect1.ContentHandler, (Aspect)aspect2.ContentHandler, (Aspect)aspect3.ContentHandler); content.Save(); Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler)); Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler)); Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler)); using (var output = new System.IO.StringWriter()) { var pc = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveAllAspects"), "", output); var handler = new ODataHandler(); //var stream = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect2Path, "\"]}")); handler.ProcessRequest(pc.OwnerHttpContext, "POST", null); result = output.GetStringBuilder().ToString(); } content = Content.Load(content.Path); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler)); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler)); Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler)); } finally { odataHandlerAcc.SetStaticProperty("ActionResolver", originalActionResolver); content.DeletePhysical(); ODataTests.CleanupTestSite(); } }
private void SetBackwardCompatibilityXmlNamespaces(bool newValue) { var pt = new PrivateType(typeof(RepositoryConfiguration)); pt.SetStaticField("_backwardCompatibilityXmlNamespaces", newValue); }
public static void SetPrivateStaticField(Type type, string fieldName, object value) { PrivateType t = new PrivateType(type); t.SetStaticField(fieldName, value); }
public void SavePng_BuildFinished() { { // MachineInfo is in the picture, so make MachineInfo as machine indepenent string for unit test puroposes string machineIndepenentInfo = "Processors: 1 | Cores: 2 | CPU Speed: 2.7GHz | Hyper Threading: Enabled | RAM: 8GB | HDD: 1 SSD"; MachineInfo mi = MachineInfo.Instance; var machineInfo = new PrivateObject(mi); // Use PrivateObject class to change private member of MachineInfo object. machineInfo.SetField("info", machineIndepenentInfo); Assert.AreEqual(MachineInfo.Instance.ToString(), machineIndepenentInfo); // Verify if internal data were updated } { // Feed DataModel with sample data DataModel dm = DataModel.Instance; var dataModel = new PrivateObject(dm); // Use PrivateObject class to change private member of MachineInfo object. dataModel.SetProperty("SolutionName", "Example.sln"); dataModel.SetProperty("StartTime", new System.DateTime(636849135031953262L)); dataModel.SetProperty("MaxParallelBuilds", 4); //<c>string</c> is ProjectUniqueName, <c>uint</c> is project build order number, <c>long</c> is project Start time, relative, counted since <c>DataModel.StartTime</c> in <c>DateTime.Ticks</c> units. Dictionary <string, Tuple <uint, long> > currentBuilds = new Dictionary <string, Tuple <uint, long> > { }; dataModel.SetField("currentBuilds", currentBuilds); List <BuildInfo> finishedBuilds = new List <BuildInfo>() { new BuildInfo("junk-finddir\\junk-finddir.vcxproj", "junk-finddir.vcxproj", 1, 399931, 54684041, true), new BuildInfo("DiskPerformance\\DiskPerformance.csproj", "DiskPerformance.csproj", 4, 59892361, 97806434, false), new BuildInfo("junk-vector-const\\junk-vector-const.vcxproj", "junk-vector-const.vcxproj", 5, 61022178, 121272755, true), new BuildInfo("WpfToolTip\\WpfToolTip.csproj", "WpfToolTip.csproj", 2, 56140367, 144319141, true), new BuildInfo("constexpr_templates\\constexpr_templates.vcxproj", "constexpr_templates.vcxproj", 3, 58330492, 151578262, true), new BuildInfo("variadic-macros-v1\\variadic-macros-v1.vcxproj", "variadic-macros-v1.vcxproj", 6, 144449121, 172642436, true) }; dataModel.SetField("finishedBuilds", finishedBuilds); Dictionary <string, List <string> > projectDependenies = new Dictionary <string, List <string> > //<c>string</c> is ProjectUniqueName, <c>List<string></c> is list of projects that <c>Key</c> project depends on { { "constexpr_templates\\constexpr_templates.vcxproj", new List <string> { "junk-finddir\\junk-finddir.vcxproj" } }, { "DiskPerformance\\DiskPerformance.csproj", new List <string> { "junk-finddir\\junk-finddir.vcxproj" } }, { "junk-finddir\\junk-finddir.vcxproj", new List <string> { } }, { "junk-vector-const\\junk-vector-const.vcxproj", new List <string> { "junk-finddir\\junk-finddir.vcxproj" } }, { "variadic-macros-v1\\variadic-macros-v1.vcxproj", new List <string> { "junk-finddir\\junk-finddir.vcxproj", "WpfToolTip\\WpfToolTip.csproj" } }, { "WpfToolTip\\WpfToolTip.csproj", new List <string> { "junk-finddir\\junk-finddir.vcxproj" } } }; dataModel.SetField("projectDependenies", projectDependenies); List <BuildInfo> criticalPath = new List <BuildInfo> { new BuildInfo("junk-finddir\\junk-finddir.vcxproj", "junk-finddir.vcxproj", 1, 399931, 54684041, true), new BuildInfo("WpfToolTip\\WpfToolTip.csproj", "WpfToolTip.csproj", 2, 56140367, 144319141, true), new BuildInfo("variadic-macros-v1\\variadic-macros-v1.vcxproj", "variadic-macros-v1.vcxproj", 6, 144449121, 172642436, true) }; dataModel.SetField("criticalPath", criticalPath); List <Tuple <long, float> > cpuUsage = new List <Tuple <long, float> >() { new Tuple <long, float>(636849135031963260, 0.0f), new Tuple <long, float>(636849135042025422, 47.36607f), new Tuple <long, float>(636849135052097336, 43.76379f), new Tuple <long, float>(636849135062946043, 36.62839f), new Tuple <long, float>(636849135073055216, 45.90309f), new Tuple <long, float>(636849135083364284, 48.84662f), new Tuple <long, float>(636849135094055281, 48.48177f), new Tuple <long, float>(636849135108063077, 98.88455f), new Tuple <long, float>(636849135118301475, 100f), new Tuple <long, float>(636849135130849521, 100f), new Tuple <long, float>(636849135142927622, 87.70002f), new Tuple <long, float>(636849135152926055, 91.4049f), new Tuple <long, float>(636849135163764355, 76.97614f), new Tuple <long, float>(636849135174642665, 89.21751f), new Tuple <long, float>(636849135188218652, 79.268f), new Tuple <long, float>(636849135199266903, 58.98672f) }; dataModel.SetField("cpuUsage", cpuUsage); List <Tuple <long, float> > hddUsage = new List <Tuple <long, float> >() { new Tuple <long, float>(636849135031963260, 0.0f), new Tuple <long, float>(636849135042025422, 64.68444f), new Tuple <long, float>(636849135052097336, 10.2781f), new Tuple <long, float>(636849135062946043, 2.541418f), new Tuple <long, float>(636849135073055216, 5.857255f), new Tuple <long, float>(636849135083364284, 8.998146f), new Tuple <long, float>(636849135094055281, 3.024021f), new Tuple <long, float>(636849135108063077, 18.93993f), new Tuple <long, float>(636849135118301475, 25.54949f), new Tuple <long, float>(636849135130849521, 1.439461f), new Tuple <long, float>(636849135142927622, 2.991249f), new Tuple <long, float>(636849135152926055, 1.817592f), new Tuple <long, float>(636849135163764355, 4.232076f), new Tuple <long, float>(636849135174642665, 6.579974f), new Tuple <long, float>(636849135188218652, 8.768057f), new Tuple <long, float>(636849135199266903, 0.652989f), }; dataModel.SetField("hddUsage", hddUsage); { // private static need to be handled through PrivateType PrivateType pt = new PrivateType(typeof(DataModel)); pt.SetStaticFieldOrProperty("projectBuildOrderNumber", 6u); } Assert.AreEqual(DataModel.Instance.SolutionName, "Example.sln"); // Verify if internal data were updated } PBMControl pBMcontrol = new PBMControl(); var graphControl = new PrivateObject(GraphControl.Instance); // Use PrivateObject class to change private member of GraphControl object. graphControl.SetField("nowTickForTest", 636849135031953262L + 172642436 + 1000); //1000 is just assumed delay for finishing (counting dependencies etc.) Window window = new Window { Width = 800, Height = 600, Content = pBMcontrol }; window.Show(); //this will draw PBMControl //window.ShowDialog(); //for debug string expected = TestUtils.GetTestFile("BuildFinished.png"); // ResultsDirectory <= this is where results should be saved. How to get value of this xaml tag? string tmpFileName = Path.GetTempFileName(); //this method return path to non-existing file in temp directory tmpFileName += ".png"; bool res = pBMcontrol.SaveGraph(tmpFileName /*pathToPngFile*/); Assert.IsTrue(res); Assert.IsTrue(ImageComparer.AreImagesEqual(expected, tmpFileName)); }
public void TestCleanup() { PrivateType projectUtilities = new PrivateType(typeof(ProjectUtilities)); projectUtilities.SetStaticFieldOrProperty("serviceProvider", null); }
public void TestMethod5() { string testMethodName = MethodBase.GetCurrentMethod().Name; string testingFolderName = GetAppPath(); Encoding enc = Encoding.GetEncoding("Shift_JIS"); string inputCsvPath; { string inputCsvFileName = testMethodName + ".CSV"; inputCsvPath = Path.Combine(testingFolderName, inputCsvFileName); string[] lines = new string[] { "12:34:56 , 0:0 , 23:59:59 , -00:00, 24:00", "2000/02/29 , 1900/1/1 , 2999/12/31 , 2000-01-01, 1999/02/29", "2000/02/29 12:34:56, 1900/1/1 0:0, 2999/12/31 23:59:59, 2000/01/01 00:00:60", "True , false , TRUE , falsE, TRUE/FALSE", "-1.2345678901234567, -0 , 123456789012345678 , 12345678" }; File.WriteAllLines(inputCsvPath, lines, enc); } string outputXlsxPath; { string outputXlsxFileName = testMethodName + ".xlsx"; outputXlsxPath = Path.Combine(testingFolderName, outputXlsxFileName); } ConvertCsvToXlsx.Program.Request request = new ConvertCsvToXlsx.Program.Request(); { request.InputCsvFileNameByArgs = inputCsvPath; request.InputCsvEncoding = enc.WebName; request.OutputXlsxFileNameByArgs = outputXlsxPath; } { var target = new PrivateType(typeof(ConvertCsvToXlsx.Program)); target.InvokeStatic("MainProcess", request); } using (var workbook = new XLWorkbook(outputXlsxPath)) { string sheetName = Path.GetFileName(outputXlsxPath); var worksheet = workbook.Worksheet(sheetName); var outputXlsxTable = worksheet.RangeUsed().AsTable(); Assert.AreEqual(new TimeSpan(12, 34, 56), TimeSpan.FromDays(worksheet.Cell(1, 1).GetValue <double>())); Assert.AreEqual(new TimeSpan(00, 00, 00), TimeSpan.FromDays(worksheet.Cell(1, 2).GetValue <double>())); Assert.AreEqual(new TimeSpan(23, 59, 59), TimeSpan.FromDays(worksheet.Cell(1, 3).GetValue <double>())); Assert.AreEqual(" -00:00", worksheet.Cell(1, 4).GetValue <string>()); Assert.AreEqual(" 24:00", worksheet.Cell(1, 5).GetValue <string>()); Assert.AreEqual(new DateTime(2000, 02, 29), worksheet.Cell(2, 1).GetValue <DateTime>()); Assert.AreEqual(new DateTime(1900, 01, 01), worksheet.Cell(2, 2).GetValue <DateTime>()); Assert.AreEqual(new DateTime(2999, 12, 31), worksheet.Cell(2, 3).GetValue <DateTime>()); Assert.AreEqual(new DateTime(2000, 01, 01), worksheet.Cell(2, 4).GetValue <DateTime>()); Assert.AreEqual(" 1999/02/29", worksheet.Cell(2, 5).GetValue <string>()); Assert.AreEqual(new DateTime(2000, 02, 29, 12, 34, 56), worksheet.Cell(3, 1).GetValue <DateTime>()); Assert.AreEqual(new DateTime(1900, 01, 01, 00, 00, 00), worksheet.Cell(3, 2).GetValue <DateTime>()); Assert.AreEqual(new DateTime(2999, 12, 31, 23, 59, 59), worksheet.Cell(3, 3).GetValue <DateTime>()); Assert.AreEqual(" 2000/01/01 00:00:60", worksheet.Cell(3, 4).GetValue <string>()); Assert.AreEqual(true, worksheet.Cell(4, 1).GetValue <bool>()); Assert.AreEqual(false, worksheet.Cell(4, 2).GetValue <bool>()); Assert.AreEqual(true, worksheet.Cell(4, 3).GetValue <bool>()); Assert.AreEqual(false, worksheet.Cell(4, 4).GetValue <bool>()); Assert.AreEqual(" TRUE/FALSE", worksheet.Cell(4, 5).GetValue <string>()); Assert.AreEqual(-1.2345678901234600m, worksheet.Cell(5, 1).GetValue <decimal>()); // Excelの仕様で15桁目以降に誤差が生じる Assert.AreEqual(0m, worksheet.Cell(5, 2).GetValue <decimal>()); Assert.AreEqual(123456789012346000m, worksheet.Cell(5, 3).GetValue <decimal>()); // Excelの仕様で15桁目以降に誤差が生じる Assert.AreEqual(" 12345678", worksheet.Cell(5, 4).GetValue <string>()); } File.Delete(inputCsvPath); File.Delete(outputXlsxPath); }
public void TestMethod1() { string testMethodName = MethodBase.GetCurrentMethod().Name; string testingFolderName = Path.Combine(GetAppPath(), testMethodName); Directory.CreateDirectory(testingFolderName); Encoding enc = Encoding.GetEncoding("Shift_JIS"); string inputCsvPathX; { string inputCsvFileName = testMethodName + ".csvX"; inputCsvPathX = Path.Combine(testingFolderName, inputCsvFileName); string[] lines = new string[] { }; File.WriteAllLines(inputCsvPathX, lines, enc); } string inputCsvPath; { string inputCsvFileName = testMethodName + ".CSV"; inputCsvPath = Path.Combine(testingFolderName, inputCsvFileName); string[] lines = new string[] { "1a,\"1,b\",1c", "2a,,2c,2d", "3a, " }; File.WriteAllLines(inputCsvPath, lines, enc); } string outputXlsxPath; { string outputXlsxFileName = testMethodName + ".xlsx"; outputXlsxPath = Path.Combine(testingFolderName, outputXlsxFileName); } ConvertCsvToXlsx.Program.Request request = new ConvertCsvToXlsx.Program.Request(); { request.InputCsvFolderName = testingFolderName; request.InputCsvEncoding = enc.WebName; request.OutputXlsxFileNameByArgs = outputXlsxPath; request.OutputXlsxForceAllCellTypeAsString = true; } { var target = new PrivateType(typeof(ConvertCsvToXlsx.Program)); target.InvokeStatic("MainProcess", request); } using (var workbook = new XLWorkbook(outputXlsxPath)) { string sheetName = Path.GetFileName(outputXlsxPath); var worksheet = workbook.Worksheet(sheetName); var outputXlsxTable = worksheet.RangeUsed().AsTable(); Assert.AreEqual(3, outputXlsxTable.RowCount()); Assert.AreEqual("1a", worksheet.Cell(1, 1).Value); Assert.AreEqual("1,b", worksheet.Cell(1, 2).Value); Assert.AreEqual("1c", worksheet.Cell(1, 3).Value); Assert.AreEqual("2a", worksheet.Cell(2, 1).Value); Assert.AreEqual("", worksheet.Cell(2, 2).Value); Assert.AreEqual("2c", worksheet.Cell(2, 3).Value); Assert.AreEqual("3a", worksheet.Cell(3, 1).Value); Assert.AreEqual(" ", worksheet.Cell(3, 2).Value); Assert.AreEqual("", worksheet.Cell(3, 3).Value); } File.Delete(inputCsvPathX); File.Delete(inputCsvPath); File.Delete(outputXlsxPath); Directory.Delete(testingFolderName); }
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); }