Can anyone help me explain how TimeProvider.Current can become null in the following class?
public abstract class TimeProvider
{
private static TimeProvider current =
DefaultTimeProvider.Instance;
public static TimeProvider Current
{
get { return TimeProvider.current; }
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
TimeProvider.current = value;
}
}
public abstract DateTime UtcNow { get; }
public static void ResetToDefault()
{
TimeProvider.current = DefaultTimeProvider.Instance;
}
}
Observations
All unit tests that directly reference TimeProvider also invokes ResetToDefault() in their Fixture Teardown.
There is no multithreaded code involved.
Once in a while, one of the unit tests fail because TimeProvider.Current is null (NullReferenceException is thrown).
This only happens when I run the entire suite, but not when I just run a single unit test, suggesting to me that there is some subtle test interdependence going on.
It happens approximately once every five or six test runs.
When a failure occurs, it seems to be occuring in the first executed tests that involves TimeProvider.Current.
More than one test can fail, but only one fails in a given test run.
FWIW, here's the DefaultTimeProvider class as well:
public class DefaultTimeProvider : TimeProvider
{
private readonly static DefaultTimeProvider instance =
new DefaultTimeProvider();
private DefaultTimeProvider() { }
public override DateTime UtcNow
{
get { return DateTime.UtcNow; }
}
public static DefaultTimeProvider Instance
{
get { return DefaultTimeProvider.instance; }
}
}
I suspect that there's some subtle interplay going on with static initialization where the runtime is actually allowed to access TimeProvider.Current before all static initialization has finished, but I can't quite put my finger on it.
Any help is appreciated.
I am quite new to TDD and am going with NUnit and Moq. I have got a method where I expect an exception, so I wanted to play a little with the frameworks features.
My test code looks as follows:
[Test]
[ExpectedException(ExpectedException = typeof(MockException), ExpectedMessage = "Actual differs from expected")]
public void Write_MessageLogWithCategoryInfoFail()
{
string message = "Info Test Message";
Write_MessageLogWithCategory(message, "Info");
_LogTest.Verify(writeMessage =>
writeMessage.Info("This should fail"),
"Actual differs from expected"
);
}
But I always receive the errormessage that the error message that the actual exception message differs from the expected message. What am I doing wrong?
This is also a question that I asked in a comment in one of Miško Hevery's google talks that was dealing with dependency injection but it got buried in the comments.
I wonder how can the factory / builder step of wiring the dependencies together can work in C++.
I.e. we have a class A that depends on B. The builder will allocate B in the heap, pass a pointer to B in A's constructor while also allocating in the heap and return a pointer to A.
Who cleans up afterwards? Is it good to let the builder clean up after it's done? It seems to be the correct method since in the talk it says that the builder should setup objects that are expected to have the same lifetime or at least the dependencies have longer lifetime (I also have a question on that). What I mean in code:
class builder {
public:
builder() :
m_ClassA(NULL),m_ClassB(NULL) {
}
~builder() {
if (m_ClassB) {
delete m_ClassB;
}
if (m_ClassA) {
delete m_ClassA;
}
}
ClassA *build() {
m_ClassB = new class B;
m_ClassA = new class A(m_ClassB);
return m_ClassA;
}
};
Now if there is a dependency that is expected to last longer than the lifetime of the object we are injecting it into (say ClassC is that dependency) I understand that we should change the build method to something like:
ClassA *builder::build(ClassC *classC) {
m_ClassB = new class B;
m_ClassA = new class A(m_ClassB, classC);
return m_ClassA;
}
What is your preferred approach?
Hi,
I am trying to use the jquery bubble popup inside the jquery carousel. the problem everything works fine. but say if i have 10 items in the carousel, display 5 at a time, hiding the remaining 5 items(which could be opened by clicking the left or right navigation). so when we move the mouse over each carousel item that is visible on the screen, we can see the bubble popup.
here, if i move the mouse over the empty area on the screen, i am still getting the bubble pop which shouldnt be visible because that particular carousel item is hidden.if i keep on moving over all the hidden items, i am able to see the bubble popup.
is there anyway to hide the bubble pop when the carousel item is not visible on the screen.
I need a URL to just test basic http connectivity. It needs to be consistent and:
Always be up
Never change drastically due to IP or user agent. (IE: 301 Location redirect/ huge difference in content... minor would be tolerable)
The URL itself has a consistent content-length. (IE: it doesn't vary from by 2kb at most, ever)
A few examples, yet none match all 3 criteria:
One example of always up: www.google.com (yet it 301 redirects based on IP location).
Another good one is http://www.google.com/webhp?hl=en. but the problem there is that based on a given holiday, the content-length can really vary.
jQuery formwizard (http://thecodemine.org/) allows you to branch a form wizard based on inputs. I am trying to figure out if it possible to rejoin the branches (and not just for the last step.)
e.g. Based on the inputs to Step 1, I'd like to present the user with a different step 2. However, after step 2, the remaining steps (step 3, 4, 5, etc.) should all be the same.
How can this be done?
Thanks!
I was tinkering with doing the setups with our unit test specifciations which go like
Specification for SUT when behaviour X happens in scenario Y
Given that this thing
And also this other thing
When I do X...
Then It should do ...
And It should also do ...
I wrapped each of the steps of the GivenThat in Actions... any feed back whether separating with Actions is good / bad / or better way to make the GivenThat clear?
/// <summary>
/// Given a product is setup for injection
/// And Product Image Factory Is Stubbed();
/// And Product Size Is Stubbed();
/// And Drawing Scale Is Stubbed();
/// And Product Type Is Stubbed();
/// </summary>
protected override void GivenThat()
{
base.GivenThat();
Action givenThatAProductIsSetupforInjection = () =>
{
var randomGenerator = new RandomGenerator();
this.Position = randomGenerator.Generate<Point>();
this.Product = new Diffuser
{
Size =
new RectangularProductSize(
2.Inches()),
Position = this.Position,
ProductType =
Dep<IProductType>()
};
};
Action andProductImageFactoryIsStubbed = () => Dep<IProductBitmapImageFactory>().Stub(f => f.GetInstance(Dep<IProductType>())).Return(ExpectedBitmapImage);
Action andProductSizeIsStubbed = () =>
{
Stub<IDisplacementProduct, IProductSize>(p => p.Size);
var productBounds = new ProductBounds(Width.Feet(), Height.Feet());
Dep<IProductSize>().Stub(s => s.Bounds).Return(productBounds);
};
Action andDrawingScaleIsStubbed = () => Dep<IDrawingScale>().Stub(s => s.PixelsPerFoot).Return(PixelsPerFoot);
Action andProductTypeIsStubbed = () => Stub<IDisplacementProduct, IProductType>(p => p.ProductType);
givenThatAProductIsSetupforInjection();
andProductImageFactoryIsStubbed();
andProductSizeIsStubbed();
andDrawingScaleIsStubbed();
andProductTypeIsStubbed();
}
Still new to Android
I want to display some data as an HTML-like ordered list (non-actionable).
Example;
Item One
Item Two
Item Three
I feel I am missing something obvious.
Thanks,
JD
I ran testng tests for my test classes,
I get the following three types of log output when I run the passing tests.
I am using org.testng.AssertJUnit.assertTrue() methods in my tests.
[testng] PASSED: testMethod1 on null(test.foo.bar.Class1)
[testng] PASSED: testMethod2 on Default test name(test.foo.bar.jar.Class2)
[testng] PASSED: testMethod3
Can any one please tell me why for some tests it says "on null" for some it says "on Default test name ... " and for some it does not say anything on the console output.
Specifically I want to make it consistent message.
Environment : linux
Testng framework : 6.3.2beta
please advise.
thanks.
I'm trying to change the default color for the options menu which is white. I want a black background for every item on the options menu. I've tried some shoots like android:itemBackground="#000000" on the item element within the menu element but it doesn't work.
I don't know if this is doable or not. Any idea would be welcome! :)
I have a GtkEntry with a GtkEntryCompletion attached to it. The Entry does something fairly expensive if the user hasn't changed the text in it for a second (to preview search results). However it's very common for the user to stop typing in order to select the correct autocompletion. So I'd like to delay the preview until the user has stopped typing and the GtkEntryCompletion is not currently suggesting anything.
GtkEntryCompletion is not a real widget however, and doesn't seem to have any way to get to whatever widget does own the CellRenderers it uses. Is there a way I can detect if it's visible or not?
I have an asp.net usercontrol that I'm using to put a bunch of HTML and Jquery logic into to be shared on several pages. This usercontrol has some dropdown boxes loaded from json calls and has no added codebehind logic.
When I use this usercontrol on a normal page it works perfectly fine, and no issues at all.
However, when I wrap the usercontrol in a div, and use a jqueryUI modal dialog, everything in the usercontrol fires twice. Not only code in the initial $(document).ready(function() {});, but also every function is also fired twice when called.
Debugging this in Visual Studio, I see that everything is first being called from the external JS file, and then again from a "script block" file that is somehow getting generated on the fly.
This script block file isn't getting generated on a page that doesn't wrap the user control in a modal.
The same happens if I use IISExpress or IIS7.
The question is, why is this script block file getting created, and why is all my jQuery logic firing twice?
--edit--
Here is the div:
<div id="divMyDiv" title="MyDiv">
<uc1:MyUserControl runat="server" ID="MyUsercontrol" />
</div>
Here is the modal logic that uses it:
$("#divMyDiv").dialog({
autoOpen: false,
height: 400,
width: 400,
modal: true,
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
Note: The problm still occurs, even if I remove the "open:" function. But, it does not occur if I remove the entire dialog block, so it is specific to this dialog call.
Is there any good framework for comparing whole objects?
now i do
assertEquals("[email protected]", obj.email);
assertEquals("5", obj.shop);
if bad email is returned i never get to know if it had the right shop, i would like to get a list of incorrect fields.
i have code like this:
The dialog does not open when i use this.
else if (json.score == -3) {
$("#dialog-unauthenticated").dialog('open');
}
but does when i use this! I have it initialized with autopen false above too.
else if (json.score == -3) {
$("#dialog-unauthenticated").dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"OK": function () {
$(this).dialog("close");
}
}
});
}
what is wrong?
close does not work either.
UPDATE: I've changed the wording of the question. Previously it was a yes/no question about if a base class could be changed at runtime.
I may be working on mission impossible here, but I seem to be getting close. I want to extend a ASP.NET control, and I want my code to be unit testable. Also, I'd like to be able to fake behaviors of a real Label (namely things like ID generation, etc), which a real Label can't do in an nUnit host.
Here a working example that makes assertions on something that depends on a real base class and something that doesn't-- in a more realistic unit test, the test would depend on both --i.e. an ID existing and some custom behavior.
Anyhow the code says it better than I can:
public class LabelWrapper : Label //Runtime
//public class LabelWrapper : FakeLabel //Unit Test time
{
private readonly LabelLogic logic= new LabelLogic();
public override string Text
{
get
{
return logic.ProcessGetText(base.Text);
}
set
{
base.Text=logic.ProcessSetText(value);
}
}
}
//Ugh, now I have to test FakeLabelWrapper
public class FakeLabelWrapper : FakeLabel //Unit Test time
{
private readonly LabelLogic logic= new LabelLogic();
public override string Text
{
get
{
return logic.ProcessGetText(base.Text);
}
set
{
base.Text=logic.ProcessSetText(value);
}
}
}
[TestFixture]
public class UnitTest
{
[Test]
public void Test()
{
//Wish this was LabelWrapper label = new LabelWrapper(new FakeBase())
LabelWrapper label = new LabelWrapper();
//FakeLabelWrapper label = new FakeLabelWrapper();
label.Text = "ToUpper";
Assert.AreEqual("TOUPPER",label.Text);
StringWriter stringWriter = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(stringWriter);
label.RenderControl(writer);
Assert.AreEqual(1,label.ID);
Assert.AreEqual("<span>TOUPPER</span>", stringWriter.ToString());
}
}
public class FakeLabel
{
virtual public string Text { get; set; }
public void RenderControl(TextWriter writer)
{
writer.Write("<span>" + Text + "</span>");
}
}
//System Under Test
internal class LabelLogic
{
internal string ProcessGetText(string value)
{
return value.ToUpper();
}
internal string ProcessSetText(string value)
{
return value.ToUpper();
}
}
Hi,
I was wondering if there was anything that provides test data for injecting into Nunit tests?
I'm sure I came across something recently that does this but I couldn't find it again.
Basically the idea is that I could use selenium and Nunit to create new customers within the system automatically.
So I could have selenium type in customer names generated from test generator (the < DataGenerator is just an imaginary class):
e.g.
dim sFirstName as string = < DataGenerator >.GetRandomFirstName()
dim sLastName as string = < DataGenerator >.GetRandomLastName()
selenium.type("firstname_field",sFirstName)
selenium.type("lastname_field",sLastName )
I've already seen SQLDataGenerator from Redgate which has a cmd line wrapper class, but I was wondering if there was anything else.
Hi,
I need to use certain font for my entire application. I have .ttf file for the same.
Is it possible to set this as default font, at application start up and then use it elsewhere in the application? When set, how do i use it in my layout XMLs?
Sample code, tutorial that can help me here is appreciated.
Thanks.
Background:
I have a django application, it works and responds pretty well on low load, but on high load like 100 users/sec, it consumes 100% CPU and then due to lack of CPU slows down.
Problem :
Profiling the application gives me time taken by functions.
This time increases on high load.
Time consumed may be due to complex calculation or for waiting for CPU.
so, how to find the CPU cycles consumed by a piece of code ?
Since, reducing the CPU consumption will increase the response time.
I might have written extremely efficient code and need to add more CPU power
OR
I might have some stupid code taking the CPU and causing the slow down ?
Any help is appreciated !
Update:
I am using Jmeter to profile my webapp, it gives me a throughput of 2 requests/sec. [ 100 users]
I get a average time of 36 seconds on 100 request vs 1.25 sec time on 1 request.
More Info
Configuration Nginx + Uwsgi with 4 workers
No database used, using a responses from a REST API
On 1st hit the response of REST API gets cached, therefore doesn't makes a difference.
Using ujson for json parsing.
Curious to Know:
Python-Django is used by so many orgs for so many big sites, then there must be some high end Debug / Memory-CPU analysis tools.
All those I found were casual snippets of code that perform profiling.
I've create a method that calculates the harmonic mean based on a list of doubles.
But when I'm running the test it keeps failing even thou the output result are the same.
My harmonic mean method:
public static double GetHarmonicMean(List<double> parameters)
{
var cumReciprocal = 0.0d;
var countN = parameters.Count;
foreach( var param in parameters)
{
cumReciprocal += 1.0d/param;
}
return 1.0d/(cumReciprocal/countN);
}
My test method:
[TestMethod()]
public void GetHarmonicMeanTest()
{
var parameters = new List<double> { 1.5d, 2.3d, 2.9d, 1.9d, 5.6d };
const double expected = 2.32432293165495;
var actual = OwnFunctions.GetHarmonicMean(parameters);
Assert.AreEqual(expected, actual);
}
After running the test the following message is showing:
Assert.AreEqual failed. Expected:<2.32432293165495. Actual:<2.32432293165495.
For me that are both the same values.
Can somebody explain this? Or am I doing something wrong?
Basically I have a tear down method that I want to log to the console which test was just run. How would I go about getting that string?
I can get the class name, but I want the actual method that was just executed.
Class testSomething() {
@AfterMethod
public void tearDown() {
system.out.println('The test that just ran was....' + getTestThatJustRanMethodName()');
}
@Test
public void testCase() {
assertTrue(1==1);
}
}
should output to the screen: "The test that just ran was.... testCase"
However I don't know the magic that getTestThatJustRanMethodName should actually be.
Hi, i am having a picture in a div when i hover the div i should get "Change" and when i leave the div the "Change" which is under div should not be visible.
Which this should happen using JQuery