nunit

Creating iOS UI components from NUnit test code

瘦欲@ 提交于 2019-12-10 13:16:40
问题 I'm trying to write a unit test for some code that programmatically creates UIButtons, but when I call this code from the test, I get a NullReferenceException . Stepping through in the debugger, it looks like UIButton.FromType() returns null. Here's the method I'm testing: public UIButton makeButton (String title, Action<IWelcomeController> action) { UIButton button = UIButton.FromType (UIButtonType.RoundedRect); // button is null here button.SetTitle(title, UIControlState.Normal); button

How to mockup Entity Framework 6 With Moq & Autofixture

蹲街弑〆低调 提交于 2019-12-10 13:14:48
问题 I am using AutoMoq but I am kinda confused how to write my first unit test because of Entity Framework's (using EF6 and code first) dbContext // in service class(constructor) private readonly MyContext context; public PriceService(MyContext context) { this.context = context; } // following would be in nunit test method. var fixture = new Fixture().Customize(new AutoMoqCustomization()); var priceService = fixture.Create<PriceService>(); When I run the unit test it crashes at Ploeh.AutoFixture

How to assert that a method has a specified attribute

我只是一个虾纸丫 提交于 2019-12-10 11:54:04
问题 Is it possible to generalize the solution to work for any type? There is a wonderful solution to asserting whether a specified attribute exists on a method: public static MethodInfo MethodOf( Expression<System.Action> expression ) { MethodCallExpression body = (MethodCallExpression)expression.Body; return body.Method; } public static bool MethodHasAuthorizeAttribute( Expression<System.Action> expression ) { var method = MethodOf( expression ); const bool includeInherited = false; return

How can I test methods which needs user to be logged

喜欢而已 提交于 2019-12-10 11:45:59
问题 I'm testing some code which needs user to be logged in. When I'm trying to log in with AccountController , it's looks like everything is working, but at AccountController (IPrincipal) User is still null. How can I properly log in (or better, can I mock it somehow)? public async Task SetupAsync() { var context = new DataContext(); var manager = new UserManager(new UserStore(context)); var accountController = new AccountController(manager); var mockAuthenticationManager = new Mock

Error while executing Run Functional Test task in VSTS

孤人 提交于 2019-12-10 11:26:46
问题 In VSTS 2015 we have build and release pipeline setup in a project which is using NUnit test framework. We are trying to configure Integration test case execution using "Run Functional Task" configuration of the task is given in the screenshot below: Visual Test Agent Deployment Task is used to Deploy the NUnit Test Agent in target machine. There is a folder that is created in Target Machine where all test assemblies are getting copied i.e. C:\TestDlls and for NUnit Adapter assemblies C:

“bool” as object vs “string” as object testing equality

烈酒焚心 提交于 2019-12-10 10:39:50
问题 I am relatively new to C#, and I noticed something interesting today that I guess I have never noticed or perhaps I am missing something. Here is an NUnit test to give an example: object boolean1 = false; object booloan2 = false; Assert.That(boolean1 == booloan2); This unit test fails, but this one passes: object string1 = "string"; object string2 = "string"; Assert.That(string1 == string2); I'm not that surprised in and of itself that the first one fails seeing as boolean1, and boolean2 are

How to find dll files containing nunit tests

我只是一个虾纸丫 提交于 2019-12-10 10:00:55
问题 I have a folder with many dlls. One of them contains nunit tests (functions marked with [Test] attribute). I want to run nunit test from c# code. Is there any way to locate the right dll? thank you 回答1: You can use Assembly.LoadFile method to load a DLL into an Assembly object. Then use the Assembly.GetTypes method to get all the types defined in the assembly. Then using the GetCustomAttributes method you can check if the type is decorated with the [TestFixture] attribute. If you want it

Unable to examine reponse headers in unit test

梦想与她 提交于 2019-12-10 09:25:03
问题 I have a unit test for an Http handler. In it I create a HttpResponse object and pass it to one of my Http handler's methods. One of my tests attempts to verify that the response headers have been set correctly: Assert.AreEqual( "gzip", response.Headers["Content-Encoding"]); However, the Headers property throws a PlatformNotSupportedException with the message "This operation requires IIS integrated pipeline mode" . The strange thing is that as I understand it, that exception is related to

nUnit tests looking for {assembly-name}.dll.config

心不动则不痛 提交于 2019-12-10 09:22:10
问题 I have a PowerShell script that shells-out to nunit-console-x86.exe to run tests in assemblies ( DLLs ) that were built earlier in the script by shelling to MSBuild to compile a VS .sln Exec { invoke-expression "$BUILD_DIR\Tools\NUnit.2.5.10.11092\nunit-console-x86.exe $full_test_assembly_name /xml:test-results/$test_results_file_name" } Some of these tests utilize System.Configuration.ConfigurationManager to load config settings. nunit-console-x86.exe searches for these config-settings in {

recursive assert on collection

好久不见. 提交于 2019-12-10 09:11:05
问题 I would like a test like this one: [Test] public void TestCollectionAssert () { var a1 = new [] { new [] { "a" } }; var a2 = new [] { new [] { "a" } }; Assert.AreNotEqual (a1, a2); //CollectionAssert.AreEqual (a1, a2); CollectionAssert.AreEquivalent (a1, a2); } to pass. My real case is more complicated, but solving this one in a generic way will do. Any ideas? 回答1: There's a useful LINQ operator called SequenceEqual() which compares two sequences for equality. SequenceEqual() walks through