简体   繁体   中英

open NUnit.Framework - the namespace or module is not defined. Referencing in F#

I am using VS2013 Professional , F# , C# and Nunit . It is worth noting that this is my first attempt with F# so question is most likely stupid and solution is obvious.

What I am trying to do is implement test cases using NUnit and use TestCaseSource attribute with TestCaseData .

Test:

namespace Legal.Tests.Helpers
open System
open System.Collections.Generic
open System.Linq
open System.Text
open System.Threading.Tasks
open NUnit.Framework
open Legal.Website.Infrastructure

type FTest() = 
    [<TestFixture>]
    [<TestCaseSource("FTestData")>]
    let ConcatTest(text : string, expected : string) =
    [<Test>]
        let actual = Saga.Services.Legal.Website.Infrastructure.FunctionModule.TestFunction text
        Assert.AreEqual expected actual
    let FTestData : seq<TestCaseData> = [ new TestCaseData (text = "x", expected = "Item1xItem2" ); new TestCaseData (text = "y", expected = "Item1yItem2" ) ] 

Function tested:

namespace Legal.Website.Infrastructure

open System
open System.Collections.Generic
open System.Linq
open System.Web

type Test(text2 : string) = 
  member this.Text = "Item1"
  member this.Text2 = text2

module functions = 
    let TestFunction (text : string) =
        let test = new Test (text2 = "Item2")
        String.Concat [test.Text; text; test.Text2]

One thing worth noting - I have created F# test file and file with function by renaming .cs file to .fs .

Problem: when I try to open any library that is not System (in this case Nuget package NUnit.Framework and Referenced project Legal.Website.Infrastructure ) I get error: the namespace or module is not defined both are referenced in Test Project and .cs tests in same directory run fine.

My question is stupid.

.fs files cannot be added to C# project like for example .vb files. To do this properly one needs to add F# project to solution, see screenshot below.

在此处输入图片说明

Implementation:

module Implementation

let Concat(text:string) = 
    "root"+ text

Test:

module Test
open NUnit.Framework

[<TestFixture>]
type Test() = 
    member this.ConcatinationTestData() = 
        [new TestCaseData("roottext","text"); new TestCaseData("root","")]
    [<Test>]
    [<TestCaseSource("ConcatinationTestData")>]
    static member ConcatinationTest(expected:string, text:string) =
       Assert.AreEqual(expected,Implementation.Concat(text))
       |> ignore

Debug -> Attach to process -> nunit-agent.exe

Result: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM