w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Accessing HostingEnvironment.MapPath() within class called by webservice / website
In the end I've found the following solution: Set the properties on the dependent files: Copy to Output Directory = Copy if newer This copies the files into the bin folder of the Hosting Environment (so it will copy it into either the WCF Service or the WebApplication from the Class Library) HostingEnvironment.ApplicationPhysicalPath then returns this location The difference is the files are being copied cross project when building (I didn't know copy if newer did this). I can therefore access the files from the applications' bin (and not from the Class Library as I was attempting before).

Categories : C#

Nunit loads all test Test data for all the test before the test gets executed
I think that's by design. NUnit is designed to clean up the environment before any test, to generate same conditions for any test independent their execution order. If Test A would change the XDocument, Test B would be run with that changes. That might led to indeterminate test results. If Test B expects changes made from Test A, then your tests are not fully isolated, that's a bad practice. If you wan't to change that behaviour, implement a lazy field and load the test data only on first access. You can increase performance if you know that you are not changing data in any of your tests, but pay attention. private static Lazy<IEnumerable> testData = new Lazy<IEnumerable>(GetExample); private static IEnumerable GetExample() { var doc = XDocument.Load("Example.xml");

Categories : Xml

Server.MapPath returning a path with a folder that doesn’t exists
I don't believe MapPath guarantees that a path exists, it just tacks your virtual path to the context path. I think your problem is that you're using HttpContext.Current.Server.MapPath try using HttpContext.Current.Request.MapPath

Categories : Dotnet

Unit test fails with NUnit Test Adapter but not with ReSharper in VS2012
I found that in VS2012 similar code would fail at run-time with the same error. If you used this method in an application, would it succeed? You're functionally iterating over a collection and removing items from it while you're still in the collection - this changes the internal indexing of the collection, invalidating the addressing of the iteration. If you'd coded it as: for(int I=0; I < Items.Count, I++) { removeItem(Items[I]); } you'd wind up with an index out of bounds error because the collection's internal indexing resets. I can't speak to ReSharper, but I'd guess that it has a more generous run-time engine than the MS nunit engine (or, for that matter, the MS runtime engine). I was doing something similar in an application where I tried to iterate through the collect

Categories : Unit Testing

iOS: HTTP service returning , how to test for this?
Have you tried using the below code to test for it if (myObject == [NSNull null]) { // handle it } else { // } "The NSNull class defines a singleton object you use to represent null values in situations where nil is prohibited as a value (typically in a collection object such as an array or a dictionary)." - Apple

Categories : IOS

NUnit says the test was successful
Your code isn't actually testing anything. It is simply setting up mocks. By themselves, mocks are useless. From what you've written, it appears you want to test the result of the getCourse1 function. An example of one of your tests might look like the following. <Test()> _ Public Sub getCourse1_WhenCalled_ReturnsExpected() ' Arrange Dim student As New Graduate() ' Act Dim course As String = student.getCourse1() ' Assert Assert.That(course, Iz.EqualTo("Graduate Course1")) ' This will fail as you expected. End Sub The test method name follows a convention described in the book The Art of Unit Testing. The test body is arranged in a sequence known as the AAA pattern.

Categories : Vb.Net

NUnit 2.6.2 TestContext.CurrentContext always null
According to this discussion you have to make sure you execute with the correct version of the NUnit testrunner. The version has to be NUnit 2.6.2. Try to run your tests with nunit-console with the correct version. Update: I did set up a new project in VS2012 and added NUnit 2.6.2 and NUnit.Runners 2.6.2 using NuGet. With the Resharper Testrunner I did get no error but also no Console output, so I did run NUnit.exe from <project-folder>packagesNUnit.Runners.2.6.2 ools This is the output I recieved: The result looks ok. I ran your example code above. However, I had to modify your code so I could run it: using System; using NUnit.Framework; [TestFixture] public class UtilitiesTests { [TearDown] public void TearDown() { //using console here just for sake o

Categories : C#

Moq: How to test a class using Nunit with an internal HttpClient?
You can't unit test it like that. It's like you mentioned: HttpClient is a dependency, and as such, it should be injected. Personally, I would create my own IHttpClient interface, implemented by HttpClientWrapper, which wraps around the System.Net.HttpClient. IHttpClient would then be passed as a dependency to your object's contructor. As follows, HttpClientWrapper can't be unit tested. I would, however, write a couple of integration tests to make sure the wrapper is well written. Edit: IHttpClient doesn't have to be a "valid" interface for HttpClient. It only has to be an interface that suits your needs. It can have as many or as few methods as you want. Picture this: HttpClient allows you to do many things. But in your project, you're only calling the GetAsync(uri).Result method, no

Categories : C#

NUnit is not releasing the .dll for my unit test project
Whenever you are building your solution. I suggest you to close the Nunit, which is loaded with your .dll. After unloading try to build, then your build will succeed. As Nunit is using you .dll. It won't allow your build to be success.

Categories : C#

NUnit or Fluent Assertions test for reference equality?
You can use NotBeSameAs() method: ref1.Should().NotBeSameAs(ref2); Its documentation says: Asserts that an object reference refers to a different object than another object reference refers to.

Categories : C#

Setting up Jenkins for Multiple Test Assemblies with Nunit
According to this issue that is a TeamCity feature, not an NUnit one. So unless you write some custom solution you can't with Jenkins. Edit: I got it working with the following Powershell step: $tests = '' Get-ChildItem -path "." -Recurse -Include "Test*.dll" | Where-Object {$_.DirectoryName -Match ".*\bin\Debug"} | foreach {$tests += ($_.toString() -ireplace ([regex]::Escape($env:WORKSPACE) + '\'), ' ')} $env:COMPLUS_Version='v4.0.30319' Invoke-Expression "c:PrivateWS esourcesNUnit-2.6.3in unit-console.exe $tests /result:nunit-result.xml"

Categories : Jenkins

NUnit test errors 'Could not load file or assembly..'
Change Target Platform of you test project to x86. Update: Also there is a bug in ReSharper 7.1.2 when running on Visual Studio 2012. Try to update ReSharper to version 7.1.3. Here's a related question: Resharper Test Runner: Could not load file or assembly 'System.Windows'

Categories : C#

NUnit test for Void function (Sending Email)
If you happen to have Visual Studio 2012 Ultimate or Premium then you can generate Fakes assembly for the System.Net.Mail assembly and use that. More info on Fakes can be found on MSDN. If you do not have VS2012 Ultimate or Premium then my answer is complete usless :)

Categories : C#

NUnit - Loads ALL TestCaseSources even if they're not required by current test
Could you do this by moving your sources instantiation to a helper method and call them in the setup methods for each set of tests? I often have a set of helper methods in my integration test suite that set up shared data for different tests. I call just the helper methods that I need for the current suite in the [Setup]

Categories : C#

Set nunit to build before test, without project building when solution is built
Have you considered adding the NUnit libraries and adapter as NuGet packages ? Doing that would make the build run and working - doing the necessary download without bothering the developer, that is NOTHING to install at all. You could choose between adding the nuget packages to the solution/source control, or let it download on demand. For some details, I have a blogpost on this approach http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/11/part-3-unit-testing-with-traits-and-code-coverage-in-visual-studio-2012-using-the-tfs-build-and-the-new-nuget-adapter-approach.aspx Note that the nuget approach doesn't require TFS, it works nicely with just VS.

Categories : Visual Studio

ServiceStack NUnit Test Debugging Connection Refused Issue
I decided to update the project to the latest ServiceStack release to start. Then, I repeated my earlier troubleshooting steps. The problem was resolved. See: ServiceStack JsonServiceClient based test fails, but service works in browser for further details.

Categories : Visual Studio 2012

Cannot find or run integration test using VS Express 2012 for Web, MVC4, WatiN & NUnit
Visual Studio 2012 won't recognise NUnit unit test fixtures. It uses its own Microsoft test framework, similar to NUnit, but not the same. The Express version that you are using won't even recognise Microsoft tests, because a test runner is not included in the Express version. Your best bet is to use the NUnit test runner outside of Visual Studio. Sadly all other test runners that plug into Visual Studio 2012 won't work with Visual Studio 2012 Express because it also doesn't allow plug-ins. If you wish to use one of the many integrated test runners within Visual Studio you will have to upgrade.

Categories : Asp Net Mvc

How to press "Enter" in Selenium WebDriver (Nunit Test Case) written in C#?
RON, there is a possibility that DOM is taking time to load after the GoToUrl call. Increase the implicit wait time so that findElement waits more time before throwing any exception. Or use explicit wiat --- http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp If still this doesnt work then use Actions class -- http://www.guru99.com/keyboard-mouse-events-files-webdriver.html

Categories : C#

Instantiate new System.Web.Http.OData.Query.ODataQueryOptions in nunit test of ASP.NET Web API controller
Looks like someone else already answered this in the comments here, but it's not a complete solution for my use-case (see comment below): ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet<Customer>("Customers"); var opts = new ODataQueryOptions<Customer>(new ODataQueryContext(modelBuilder.GetEdmModel(),typeof(Customer)), request);

Categories : Asp Net Web Api

In ASP.NET, what determines the value of HostingEnvironment.IsDevelopmentEnvironment?
The decompiled code of this property is as follows: public static bool IsDevelopmentEnvironment { get { return ((AppDomain.CurrentDomain.GetData(".devEnvironment") as bool?) == true); } } But I couldn't fin where this value is set.. :-(

Categories : Asp Net

Jenkins generate nunit report nunit-report.xml
I've added this line to nant build script instead of adding a step to jenkins: formatter type="Xml" outputdir="${main-directory}BuildResults" usefile="true" extension=".xml"/> Making it this: <target name="build" description="Build Solution and run tests"> <echo message="Building the release configuration" /> <exec program="${msbuild}" commandline='"${my-solution}" /v:m /nologo /property:WarningLevel=0 /t:Rebuild /p:Configuration="Release" /p:Platform="Any CPU"' /> <echo message="Running unit tests" /> <nunit2> <formatter type="Plain" /> <formatter type="Xml" outputdir="${main-directory}BuildResults" usefile="true" extension=".xml"/> <test assemblyname="${main-directory}P

Categories : Jenkins

Using Server.MapPath to save a file
You can access it through the current context HttpContext.Current.Server.MapPath("~/App_Data/stored"); to get the full file path : var filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data/stored"), package.Id + ".zip");

Categories : Asp Net

Using Server.MapPath() to generate img src, not working
APP_Data is a restricted folder intended for Datasources such as Database only. ASP.Net will not deliver a file in here - try it by going to the URL for that image directly (I.E www.mysite/App_Data/5/62.jpg ) and you will see the error message HTTP Error 403 - Forbidden. Put your images in a folder outside of this and you will be fine, such as a folder in the root Called Images

Categories : Asp Net

Server.MapPath() with IIS URL Rewrite Module 2.0
I was looking for the same thing so I gave it a try in a test app. It appears that Server.MapPath() does not acknowledge URL Rewrite Module rules. Here is how I tested using an empty web project (Razor syntax): Rewrite rule: <system.webServer> <rewrite> <rules> <rule name="Rewrite rule1 for test1"> <match url="^test1(.*)" /> <action type="Rewrite" url="{R:1}" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer> cshtml: <p> The URL for this page is @Request.Url.AbsoluteUri . <br /> MapPath of /test1 is @Server.MapPath("~/test1") <br /> MapPath of / is @Server.MapPath("~/") </p> I

Categories : Iis

Cannot use Server.MapPath to access a external file
Server.MapPath works only with files that are inside the website and is used by specifying a relative location: string configFile = Server.MapPath("~/App_Data/config.xml.config"); If you want to access a file from some other location you will have to manually provide the absolute path to it: string configFile = @"c:worksome_folderconfig.xml.config";

Categories : C#

Why won't File.copy work with Server.MapPath
Server.MapPath is a secure method, and requires that you have AspEnableParentPaths set to true for your application. http://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx

Categories : Asp Net

How we Redirect one Page to AnotherPage with Server.MapPath
you don't need MapPath here, since you have relative path you can directly call Response.Redirect Response.Redirect("~/ReportPage.aspx"); Server.MapPath will return physical path of given file. For example when we need to read TEXT file inside root folder var lines = File.ReadAllLines(Server.MapPath("~/temp.txt")); But in your case no need of a Server.MapPath

Categories : C#

httpcontext.current.server.mappath and unit testing
You need to abstract out the loading of the XML file. Such as; class WebContentLocator : IContentLocator{ public string GetPath(string relativePath) { return HttpContext.Current.Server.MapPath(relativePath); } } class TestContentLocator : IContentLocator{ string _contentRoot; public TestContentLocator() { _contentRoot = ConfigurationManager.AppSettings["ContentRoot"]; } public string GetPath(string relativePath) { return Path.Combine(_contentRoot, relativePath.Replace("~", string.empty); } } interface IContentLocator { string GetPath(string relativePath); } and in your test inject the TestContentLocator into the code that is doing the XML loading, which would by default be using the WebContentLocator. Fds.ReadXml(_content

Categories : Asp Net Mvc

What using directive do I use for Server.MapPath in a separate .cs file in WebMatrix?
You can assign the Server property to a variable to save a bit of typing: var server = HttpContext.Current.Server; var file = server.MapPath("~/SomeDirectory/Somefile"); To answer the question posed in the title of your post - the using directive you need in the class file is System.Web: using System.Web; I don't know of any "cheat sheet" as such. Experience and a growing familiarity with MSDN help, as does Resharper if you can afford it and have the full version of Visual Studio.

Categories : C#

@Value returning null
Are you passing valid value expressions? For properties placeholder you can use something like: @Value("${directory.extDirectory}") You can also use Spring EL and get all the goodness from it using the #{value} check the docs here Is also possible to assign a default value in case the property is not found @Value("${directory.extDirectory:defaultValue}")

Categories : Spring

Why is this returning a NULL
I bet this runs on a 64bit system and your code looks like this: int main() { char *str=get_str(); printf("received str %s with len %d ", str, strlen(str)); } char *get_str() { char *str; int slen=get_strlen(); str=(char *)malloc(sizeof(char)*slen); set_str(str); printf("returning str %s with len %d ", str, strlen(str)); return str; } To fix this, add the appropriate prototyping: char *get_str(); before the function's first usage. On (most?) 32bit systems pointer are 32bit wide, which is the same size as an int to which the compiler defaults the function as the prototpye is missing, so although using a wrong type the value gets pass back up successfully. The latter won't work anymore on a 64bit system as pointers (on most systems) are wider than a

Categories : C

Why isn't this returning null?
You should use isNaN(value); to check for NaN Because: console.log(NaN === NaN); // false! NaN is not equal to itself. This may seem weird but it makes sense if you think about the nature of NaN. Let's say you have this code: var a, b, c; // a = 0;oops a is still undefined so we'll get NaN if we do an operation with it b = 5; c = 6 if (a + b === a + c) { console.log("math error?"); } You don't want to come to the seeming conclusion that 5 === 6.

Categories : Javascript

django test client always returning 301
Standardly I've figured out the answer while writing the question... hopefully this will be useful to somebody else! Somehow the SSL config snuck into my dev settings. In particular I've had the following SSL_FORCE_HOST = 'example.com' enabled, which seems to be a problem - after disabling it in dev, the problem disappeared.

Categories : Django

Returning NULL Structure
Your function return type is CvBox2D, so you can't convert a (NULL) pointer to it. If you really need to return "nothing" if the check inside the function fails, you can change the return type to a pointer to CvBox2D: CvBox2D* function() { ... } You will also have to change the way the returned object is created inside your function. Note that using raw pointers in C++ usually isn't a good idea. Take a look at std::shared_ptr (available in C++11) if you think you really have to use pointers.

Categories : Opencv

imageItem returning null in c#
The as operator is like a cast operation. However, if the conversion isn't possible, as returns null instead of raising an exception so if current item in layer.Items is not ImageItem you get null assigned to imageItem in this line ImageItem imageItem = item as ImageItem;

Categories : C#

JSP getAttribute() returning null
You are not typecasting it to String. request.getAttribute() will return an Object. Try using this and see if it works: String value = (String)request.getAttribute("colnames"); Or <%= (String)request.getAttribute("colNames") %> Why are you using forEach here? You just need to display a String right? Also, shouldn't var="col" be ------> var = "colNames" <tr> <c:forEach items="${param.colNames}" var="col"> <td>${col}</td> </c:forEach> </tr>

Categories : Java

PHP: array_search returning null
Assuming that your array will always contain contiguous numbers, and you can verify that your second SQL call returns one of those numbers, I would say something like $value = $freeRooms[$roomNb] I'm personally unfamiliar with how array_search executes, however if you wanted to write your own, I assume it would look something like this function IndexOf($searchValue,$array) { $i = 0; for( $i = 0; $i < count($array); $i++ ) if( $array[$i] == $searchValue ) return $i; }

Categories : PHP

LayoutParams returning null
Here tc.getLayoutParams() you haven't given it any params yet so it will return null. Maybe you meant descriptiontv.getLayoutParams() Edit Try changing params.leftMargin = 30; params.rightMargin = 30; to params.setMargins(30, 0, 30, 0); And change LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams)tc.getLayoutParams(); to LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

Categories : Android

twitter api 1.1 - returning NULL
It works fine for me. My results are here: http://pastebin.com/FB1zpuuT Start by verifying that you can connect to this in your web browser. https://api.twitter.com/1.1/statuses/user_timeline.json If you can connect to that, you will see an error message. If not, the problem is likely your network blocking Twitter, or Twitter blocking your ip address.

Categories : PHP

combobox returning null value in c#
Reason is clear that you have no text selected You've to select any item in combobox first. To do so try any of the following Set SelectedIndex to some valid index Set SelectedItem to a valid item in combobox through code Select an item in combobox by clicking it Then use following code MessageBox.Show(comboBox1.SelectedText); or if(comboBox1.SelectedItem != null)//check for null since `SelectedItem` can be null when nothing selected MessageBox.Show(comboBox1.SelectedItem.ToString()); Note: As @tim pointed in comments SelectedText approach won't work when DropDownStyle set to DropDownList. In that case you've to use SelectedItem approach

Categories : C#

© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.