Click here to Skip to main content
14,930,203 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345320-Sep-17 22:56
professionalMember 1286345320-Sep-17 22:56 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345322-Sep-17 23:46
professionalMember 1286345322-Sep-17 23:46 
QuestionUnable to cast object of type 'System.DBNull' to type 'System.String'. Pin
samflex19-Sep-17 5:35
Membersamflex19-Sep-17 5:35 
AnswerRe: Unable to cast object of type 'System.DBNull' to type 'System.String'. Pin
Richard Deeming19-Sep-17 6:04
mveRichard Deeming19-Sep-17 6:04 
GeneralRe: Unable to cast object of type 'System.DBNull' to type 'System.String'. Pin
samflex19-Sep-17 9:17
Membersamflex19-Sep-17 9:17 
QuestionDot Net Core 1.1 Static files(css,fonts,js) are not getting loaded when I am deploying my site in a Sub Domain Pin
IncodeSolutions18-Sep-17 19:58
MemberIncodeSolutions18-Sep-17 19:58 
QuestionNeed a article on repository and data access code unit testing Pin
Mou_kol17-Sep-17 22:54
MemberMou_kol17-Sep-17 22:54 
AnswerRe: Need a article on repository and data access code unit testing Pin
F-ES Sitecore18-Sep-17 0:07
mveF-ES Sitecore18-Sep-17 0:07 
First of all I'd ask why you don't want to use a mocking framework, it'll make your life a lot easier. However if you don't want to use one then you can use a technique called self-shunting. That is where the test class itself acts as the mocked object and you can write any code you want in your "mocked" methods.

In this brief example I have a ProductService class that uses an IProductRepository to access the products. There's only a simply Get method but it gives you the rough idea. So in my unit test I make the test class implement IProductRepository and I mock the Get method in the test class itself.

public interface IProductRepository
{
    Product Get(int id);
    void Add(Product product);
}


public class ProductService : IProductService
{
    private IProductRepository productRepository;

    public ProductService(IProductRepository productRepository)
    {
        this.productRepository = productRepository;
    }

    public Product GetProduct(int id)
    {
        return this.productRepository.Get(id);
    }
}


Unit test

[TestClass]
public class ProductServiceTests : IProductRepository
{
    private Product Product { get; set; }

    [TestMethod]
    public void WhenValidGetProductIsCalledProductIsReturned()
    {
        // arrange

        this.Product = new Product { ID = 1, Name = "Test product" };
        ProductService ps = new ProductService(this);

        // act

        Product p = ps.GetProduct(1);

        // assert

        Assert.AreSame(this.Product, p);
    }

    [TestMethod]
    public void WhenInvalidGetProductIsCalledProductIsReturned()
    {
        // arrange

        this.Product = new Product { ID = 1, Name = "Test product" };
        ProductService ps = new ProductService(this);

        // act

        Product p = ps.GetProduct(2);

        // assert

        Assert.IsNull(p);
    }

    public void Add(Product product)
    {
        throw new NotImplementedException();
    }

    public Product Get(int id)
    {
        if (this.Product.ID == id)
        {
            return this.Product;
        }
        else
        {
            return null;
        }
    }
}

PraiseRe: Need a article on repository and data access code unit testing Pin
Mou_kol19-Sep-17 23:56
MemberMou_kol19-Sep-17 23:56 
Questionvb.net 2010 web form app point to correct .net framework Pin
dcof15-Sep-17 14:49
Memberdcof15-Sep-17 14:49 
QuestionAdding API's to website Pin
Member 1271965814-Sep-17 10:35
MemberMember 1271965814-Sep-17 10:35 
QuestionHow do I handle nulls in RadioButtonList in Repeater? Pin
samflex13-Sep-17 9:50
Membersamflex13-Sep-17 9:50 
AnswerRe: How do I handle nulls in RadioButtonList in Repeater? Pin
Kornfeld Eliyahu Peter13-Sep-17 10:29
professionalKornfeld Eliyahu Peter13-Sep-17 10:29 
GeneralRe: How do I handle nulls in RadioButtonList in Repeater? Pin
samflex13-Sep-17 11:04
Membersamflex13-Sep-17 11:04 
AnswerRe: How do I handle nulls in RadioButtonList in Repeater? Pin
Richard Deeming14-Sep-17 1:51
mveRichard Deeming14-Sep-17 1:51 
GeneralRe: How do I handle nulls in RadioButtonList in Repeater? Pin
samflex14-Sep-17 3:58
Membersamflex14-Sep-17 3:58 
QuestionAny utilities for replicating Web Site files through intermediary drop into web site testing location. Pin
Blake Miller6-Sep-17 12:27
MemberBlake Miller6-Sep-17 12:27 
Questionusing asp.net c# Pin
Member 133738734-Sep-17 18:58
MemberMember 133738734-Sep-17 18:58 
AnswerRe: using asp.net c# Pin
User 418025418-Sep-17 3:21
MemberUser 418025418-Sep-17 3:21 
QuestionHttp to Https URL rewriting Pin
Member 1129085529-Aug-17 2:37
MemberMember 1129085529-Aug-17 2:37 
AnswerRe: Http to Https URL rewriting Pin
A_Griffin29-Aug-17 3:36
MemberA_Griffin29-Aug-17 3:36 
GeneralRe: Http to Https URL rewriting Pin
Member 1129085530-Aug-17 1:40
MemberMember 1129085530-Aug-17 1:40 
GeneralRe: Http to Https URL rewriting Pin
Nathan Minier13-Sep-17 2:04
professionalNathan Minier13-Sep-17 2:04 
QuestionFile Upload and Export option with VS 2015 Pin
netbrain software28-Aug-17 23:00
Membernetbrain software28-Aug-17 23:00 
AnswerRe: File Upload and Export option with VS 2015 Pin
A_Griffin29-Aug-17 0:17
MemberA_Griffin29-Aug-17 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.