.net - Starting Out With Unit Testable Code?

Apr 18, 2011

I've read about creating factories, and unit testing driven development and how it actually saves you time during the debug phase of development. I'm using some libraries for an entity framework (Entity Spaces, since we are not on dot-net 4.0 yet)

Since getting started seems to be the hardest part for me to wrap my brain around, How would I create a factory for an object that is unit testable on a simple method like so?

[Code]...

However when I call video, its giving me "possible null reference exceptions" errors, and indeed its throwing a null reference. If my constructor is declared public and shared, and is creating a new object, then returning it, why is it giving me null exceptions?

View 1 Replies


ADVERTISEMENT

C# - Architecting A Testable API Client?

Apr 9, 2010

I have to interface with an web API. It accepts post requests and returns XML data. It requires a lot of asynchronous processing on the client side, so that it can retry multiple times in case of failure without interrupting the main client process. The code needs to be well tested. I am creating a mock version of the API to test against locally, and writing unit tests which connect to it. Is this a good approach for testing? Should I also have versions of the client API that fake a connection to the server and do not actually connect? (just return mock data)I am trying to also figure out the best architecture for the request / response classes. Should I just serialize the response into a class? Should have have some sort of mapping file that maps XML fields to class properties? I was thinking about having a request class for each request, which follows an interface. I could then have a ApiRequestSender class, and also a AsyncApiRequestSender class, which sends the request and gets the response. The only thing I am confused about there is how to get the correctly typed Response, since there are 4.

View 2 Replies

Application Which Communicate With One Data Logger Unit (temperature Monitoring Unit)

Jul 21, 2010

I have written one application which communicate with one data logger unit (temperature monitoring unit) and download records after some interval. Unit continuously send current temperature which I have to show on screen and after each one hour I have to download log (all records saved inside unit at max 1024) from unit.

Now problem is after downloading log, application get hang or what we called working in background and resume after some time. If I pause debugger in visual studio 2008 it show control at application start (sub main) with message as "application will resume here after completing execution of current function". There is nothing in output window. So how can i trace is there any events got spool or what actually application doing in background.

View 1 Replies

Ensure That Certain Code Is Run As A Unit?

Feb 3, 2011

So when that code run the program don't switch.Say I want to

Open a file
Write something
Close a file

Way when I open a file, another thread want to open that same file. That means open a file get executed twice.

View 4 Replies

VS 2008 Unit Converter Handling Multiple Unit Types

Apr 12, 2011

Does anyone have a nice sample of a unit convertor handling multiple unit types that I can integrate in my application? I have found this one, but it is only handling one type of unit. For example I want to convert weight as well as volume from and to imperial units.

View 8 Replies

.net - Unit Test Fails, Tested Code Works?

Aug 14, 2009

I have a simple unit test which tests that a validation function picks up a specific validation issue. The validation item returns a simple object with Item & Message properties. I've written a unit test for this function but this always fails even though I know the function works as expected.

<TestMethod()> Public Sub ContractNote_ValidateForManualInputTest_TradeOrderValueComparison()
'Can't get this test to work even though validation works!
Dim CN As ContractNote = New ContractNote
Dim Trade As New TradeOrder

[code].....

I've implemented IComparable on ValidationItem (I have a separate unit test which confirms this works). Am I Using CollectionAssert correctly?

View 1 Replies

WPF Starting Animation From Code Giving Error

Mar 24, 2009

I'm trying to trigger an animation declared in the window's XAML file from the window's vb code when an event is raised (calling a function), like a window's "loaded" event.

Here's how I declare the animation (as a storyboard):

Dim StartAnimation As Storyboard = DirectCast(FindName("ServiceOn"), Storyboard)
Dim StopAnimation As Storyboard = DirectCast(FindName("ServiceOff"), Storyboard)

And here's the code for the function that is failing:

[Code]...

View 2 Replies

VS 2005 Database Coding - Modify The Above Code To Fetch All The Rows Starting From The Begining From The Database?

Jul 13, 2009

I did the following


Imports System.Data
Imports System.data.OleDb
Public Class Form1
Dim con As OleDb[code].....

By this i can fetch only one row(the last row) of the access....how to modify the above code to fetch all the rows starting from the begining from the database..........

View 9 Replies

C# - Decompiling .Net Assembly Produces Code With Invalid Member Variable Names; Names Starting With $STATIC$?

Sep 5, 2011

I am doing work for a client who has lost the source code for one of their VB.Net WinForms applications. The assembly they have is not obfuscated at all. I am trying to recover as much of the source as I can as C# source and have tried several tools for decompiling assemblies, including Reflector, ILSpy and JustDecompile (all the latest versions), but they all produce code with a huge number of errors in them. Because of the large number of errors in the generated code, I am going to ask about the specific errors (in different questions), get more directed answers and in this way try shed some light on why all the tools are having difficulty decompiling this assembly. This question pertains to the fact that the code generated by all these tools always have a large number of invalid member variables (fields) such as the following:

private short $STATIC$Report_Print$20211C1280B1$nHeight;
private ArrayList $STATIC$Report_Print$20211C1280B1$oColumnLefts;
private StaticLocalInitFlag $STATIC$Report_Print$20211C1280B1$oColumnLefts$Init;

why the generated code has these invalid member variables?

View 3 Replies

Get The Unit In A Currency?

Jan 16, 2010

What code can you use to get the unit in a currency?

For example in 10,340.55 there is:

10 units for a thousand.
3 units for hundreds
4 units of tens.
1 fifty cent
1 five cent.

View 4 Replies

Could Not Run Unit Test With Mock

Apr 18, 2012

I tried to make an unit test for this method which is pretty simple only add an object into the data base and if it works well returns true

[Code]...

View 1 Replies

Developing A Unit Testing API?

Dec 29, 2010

I have been assigned a task of exploring unit testing using tools available in the market.My question is how do i write an API that would help in writing unit test cases.Example i can use nunit to write something like this to check whether file exists in the given location.

<Test()> _
Public Sub CheckOutputFileInfo()
ReportPath = "D:temp est.txt"

[code].....

View 3 Replies

Get A Documentation For Unit Tests In VS TS?

Aug 27, 2009

When i perform unit testing on routines, using the unit testing framwork provided by VSTS, i need to get a output of the unit test and result on to a document (documentation). how do i do i do this?

View 1 Replies

Logic To Calculate Age And Age Unit

Apr 10, 2012

I want to create a logic to calculate the age and unit from entered birth date. eg: If the difference between birth date and current date is >= 24 months, I will want it to display the age in years. If >= 8 weeks, I will want it to display it in months and so on here's my code

[Code].....

View 9 Replies

Rounding Up To The Nearest (Unit 10)?

Jul 9, 2010

How do I go about rounding up to the nearest (Unit 10) ie Codes Below

IfVal(TimeHalfFareTextBox.Text = $/£ 0.05)
Then roundup
to $/£ 0.10. Or it might be .....

[Code]....

View 6 Replies

Speed Up The Unit Testing?

Aug 29, 2009

In the project that i;m currently working on i;m not allowed to touch GUI for anyreason that includes program testing. I'm in bit of s frustration becuase prior to this all must application were developed and tested using GUI. Typicvally it wold take a me a week to develop an app now it taking more than that. Especially the TDD with Unit testing. The documentation kills more time too......

View 4 Replies

Unit Testing - Experiences Using Moq With .Net?

Apr 28, 2009

I really like the moq mocking framework. I've used it on several projects. Unfortunately, one of my customers is demanding we use VB.Net. Not my preference, but hey, .Net is .Net, right?I've heard that moq has some trouble with VB. Is this true? Is so, what sorts of trouble? I would expect it to work fine given the language agnostic nature of .Net.

Should I look into using some other mocking framework for use with VB?

View 2 Replies

Unit Testing And Could Not Load Dll?

Sep 1, 2011

I have a unit test project and a project A that refers to the dll B. When make changes to the dll B and build my solution again I get an error meassage: could not load dll B or one of it's dependencies when i try to run the test project. The dll B does not exists in the references of the test project.

View 11 Replies

Use Imaginary Unit In Program?

Apr 14, 2010

I want to know is their a way to display the imaginary unit i. For example when I calculate the square root of -25, I want the program to display the answer 5i instead of NaN (Not a Number). So is their a way to display imaginary numbers and even complex numbers in visual basic 2008.

View 8 Replies

Using Resources In A Unit Test?

Sep 10, 2009

I created some string resources in My.Resources. I want to use those resources in my unit tests.How do I expose these resources to my unit test project?I tried simply setting the Access Modifier to "Public" for the resources. This made it so that I can compile the code, but it is ignoring the culture setting.

Bo.My.Resources.Culture = New CultureInfo("en-GB", False)
LocaleTest(Bo.My.Resources.Yes, "Yea")

View 2 Replies

Using XML DataSource In Unit Test

Mar 3, 2010

I am writing a test unit (in MSTest) that consumes an XML file located in the testing project. I have this (solution name is BusinessLogic, project name is BusinessLogicTest):

Public TestContext As TestContext
<TestMethod()>
<DeploymentItem("BusinessLogic.BusinessLogicTestTestData.xml")>
<DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
"|DataDirectory|TestData.xml", "Row", DataAccessMethod.Sequential)> _
Public Sub ConvertIntToRoman_DataDrivenTest
[Code] .....

However, when I run the test I get an error: The unit test adapter failed to connect to the data source or to read the data. I belive it's something to do with my DeploymentItem and/or DataSource, however, I cannot find an example (in VB) that works anywhere.

View 2 Replies

.net - NullReferenceException Unit Testing Error

Sep 18, 2011

Doing some homework on unit testing and in all honestly i just don't get why i get this error.

i got a simple method that select all text when tab and testing if the actually textbox1 is selected. I just don't get why i'm getting a nullReferenceException at target.txtbox1_Enter(sender, e)

Private Sub txtbox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtbox1.enter
Dim txtBox As TextBox

[Code].....

View 1 Replies

.net - Unit Testing In Visual Studio?

Apr 1, 2011

I'm wanting to create a load of unit tests to make sure my stored procedures are working, but i'm failing (i'm new to tests in visual studio).Basically I want to do the following:

<testclass()>
Dim myglobalvariable as integer
<testmethod()>

[code]....

The problem is because the tests don't run sequentially, tests 2 and 3 fail because the global variable isn't set.

View 4 Replies

Best Practice Example Of An MVP Implementation Of Unit Testing

May 4, 2009

Can anyone point me towards a complete scenario using MSTest,vb.net, with or without mocks,MVP (supervising controller)

View 1 Replies

C# - Rounding To The Best Unit Without Losing Precision

Jan 26, 2010

I receive a decimal number with a maximum of 4 digits after the "." and I know this number is in milligram.

I have to find the best matching unit (milligram, gram, kilogram) for the number.

for an example if I receive

edited

116000000.0000 milligram, it's going to return 116.0000 kilogram
66990000.0000 milligram, it's going to return 66.9900 kilogram
49000010.0000 milligram, it's going to return 49000.0100 g

[Code]....

View 6 Replies

Convert A Metric Unit To Standard?

Oct 13, 2011

how to convert a metric unit to standard. I will be converting Feet/Inches to Meters/Centimeters and vise versa as well as pounds/ounces to kilograms/grams and vise versa. I can input the values into my Textbox to where it reads " x'y" ," however, when I go to code the Convert button (the same button has to be used for all conversions) how to separate out the text and then perform the conversion.

View 7 Replies

Report Progress Of Unit Test?

Oct 5, 2010

Is there currently any possible way to report progress of my unit test? I have a test that could take up to a hour, and I don't want to sit there not knowing what % it is done with. I have tried writing with debug.print and trace.writeline, neither of which seem to work.

View 1 Replies

Set Default Value For A Unit Type Parameter?

Apr 12, 2011

I want to include an optional parameter in a function statement that is of the type Unit. For example:

Public Shared Function NewTable(Optional ByVal TableWidth As Unit) As Table

Optional parameters require a default value, but I cannot figure out how to set a default value for a Unit type.

View 7 Replies

Stop Unit Tests From Running?

Jun 11, 2010

I would like to prevent all subsequent unit tests from running when certain conditions are met in a unit test. Is this possible in Visual Studio 2005?

View 2 Replies

Unit Test And SQL Database Connection

Jun 3, 2009

I am having a problem with a unit test I have created. First time doing this so I am not sure why I am getting this error [code]Test method ETDS_Unit_Tests.LoginTest.ValidateUserNameTest threw exception: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server).This is the same connection that my software is using, and the software runs fine, only the unit test is failing. What I am doing wrong? It Seems to fail one time for each datarow in the table.Also, I am using a Linq Query in the method that I being tested. I believe that this may be what is causing my error.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved