Why the XUnit attributs aren't recognised? - vb.net

I installed the libraries xUnit with NuGet, and added references but I have errors because of the attributes [Theory], [InlineData("11/12/2011","2011-11-12")] and [Fact].
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Linq
Imports System.Text.RegularExpressions
Imports FluentAssertions
Imports Xunit
Imports System
Imports System.Diagnostics
Imports Xunit.Extensions
Public Class XUnitClassTest
[Theory]
[InlineData("11/12/2011","2011-11-12")]
Public Sub test(input As String, output As String)
Dim pattern As String = "\d+|[A-Za-zÀàÂâÄäÇçÉéÈèÊêËëÎîÏïÔôÖöÙùÛûÜü']+"
Dim matchList As MatchCollection = Regex.Matches(input, pattern)
Dim matchArray(matchList.Count - 1) As Match
matchList.CopyTo(matchArray, 0)
Dim manager As Processeur = New Processeur
manager.GetData(matchArray.Select(Function(a) a.ToString())).Should().Be(output)
End Sub
[Fact]
Public Sub FactMethodName()
Write(DateTime.Parse("1658").ToString())
End Sub
Public Shared Sub Write(format As String, ParamArray param As Object())
Console.WriteLine(format, param)
End Sub
End Class

You are using C# attribute syntax in VB.NET.
VB.NET syntax would be
<Fact>
Public Sub FactMethodName()
Write(DateTime.Parse("1658").ToString())
End Sub
and so on.

Related

How would I fix this issue; Imports System.Security.Cryptography will not function with Imports System.Net

I am making a program in VB.Net which requires the imports of four import thingamajiggys. However, Imports System.Security.Cryptography will not work alongside each other imports.
I've tried arranging the order they work in. Imports System.Security.Cryptography will not work at all with Systems.Net, but it will work alongside Imports System.Text and Imports System.IO
Imports System.Security.Cryptography
Imports System.IO
Imports System.Net
Imports System.Text
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Function SHA1(ByVal Content As String) As String
Dim Molecule As New Security.Cryptography.SHA1CryptoServiceProvider
Dim bytestring() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
bytestring = Molecule.ComputeHash(bytestring)
Dim finalstring As String = Nothing
For Each bt As Byte In bytestring
finalstring &= bt.ToString("x2")
Next
Return finalstring
End Function
A red wiggled line (like the spelling mistake in Word) appears under Security.Cryptography.SHA1CryptoServiceProvider but only when Systems.Net has been imported. Why does this happen?
You are getting the red wiggly line because System.Net also has a 'Security' namespace and it's trying to find Cryptography.SHA1CryptoServiceProvider in there.
To fix it either type
Dim Molecule As New System.Security.Cryptography.SHA1CryptoServiceProvider
or
Dim Molecule As New SHA1CryptoServiceProvider
You can use aliases.
Imports CryptoSecurity = System.Security
Imports MyNet = System.Net
Then in code
Dim Molecule As New CryptoSecurity.Cryptography.SHA1CryptoServiceProvider
You can use any names that make sense to you for the alias.

mshtml HTMLDocument createDocumentFromUrl in vb.net

How to use createDocumentFromUrl in vb.net. I got information like we should use IPersistStreamInit interface if we want to work on this. So i want an example showing this.
I would not recomend going alone into that interface, But I am guessing that you are doing this in a dll/cmd line so you can't use the winform solution so you can use htmlAgility pack and you can download it as a nuget HtmlAgilityPack
But If you have to go the interop way you can check out this question Getting the HTML source from a WPF-WebBrowser-Control using IPersistStreamInit
And the only thing you need to add for vb is this
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose()
GC.SuppressFinalize(Me)
End Sub
But using the agility pack you can do it like this:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Net
Imports System.IO
Imports HtmlAgilityPack
Class Program
Private Shared Sub Main(args As String())
Dim wc As New WebClient()
Dim doc As New HtmlDocument()
doc.Load(wc.OpenRead("http://google.com"))
End Sub
End Class

"New": Too many arguments

I made a "custom" form as seen below. When I say:
Dim nSplash As New frmSplash(nBitmap)
It is telling me that there are "too many arguments for Public Sub New".
I do not see why it is mocking about it.
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Namespace AlphaWindow
Public Class frmSplash
Inherits Form
Public Sub New(ByRef uBitmap As Bitmap)
Me.Size = uBitmap.Size
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
APIHelp.ShowTopmost(Me)
Me.SelectBitmap(uBitmap)
End Sub
(...)
' Class to assist with Win32 API calls
Class APIHelp
Private Const SW_SHOWNOACTIVATE As Integer = 4
Private Const HWND_TOPMOST As Integer = -1
(...)
End Class
End Namespace
The problem is not the Namespace, but when a namespace is included, the form has to be called by "Namespace.Form" instead of just "Form".

VB silverlight for windows phone

I am writing an application in VB for windows phone 7.5
but it has some bug
Imports System.IO
Imports System.IO.TextReader
Imports System.Xml
Imports System.Windows.RoutedEventArgs
Imports System.Windows.RoutedEvent
Imports System.ComponentModel
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Microsoft.Phone.Tasks
Imports System.Xml.Linq
Imports System.Net.NetworkInformation
Imports Microsoft.VisualBasic.CompilerService
Partial Public Class MainPage
Inherits PhoneApplicationPage
Public Sub New()
InitializeComponent()
End Sub
Private Sub MainPage_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Final.Items.Clear()
If NetworkInterface.GetIsNetworkAvailable Then
Dim cl As New WebClient
AddHandler cl.DownloadStringCompleted, AddressOf cl_DownloadStringCompleted
cl.DownloadStringAsync(New Uri("http://web.com/xml.xml"))
Else
MessageBox.Show("check your internet connection")
End If
End Sub
Private Sub cl_DownloadStringCompleted(sender As Object, e As System.Net.DownloadStringCompletedEventArgs)
Dim doc = XDocument.Parse(e.Result)
Dim names = XDocument.Parse(e.Result)
Dim result_name = names.<Data>.<Entry>
For Each result In doc.<Data>.<Entry>.<tag>
Dim item As New ListBoxItem
item.Content = result.Value
AddHandler item.Tap, AddressOf ItemTap
Final.Items.Add(item)
Next
End Sub
Private Sub ItemTap(sender As Object, e As GestureEventArgs)
Dim lbi As New ListBoxItem
lbi = sender
Dim url As New Uri("/" & lbi.Content & ".xaml", UriKind.Relative)
Me.NavigationService.Navigate(url)
End Sub
End Class
it finds a bug at Dim url As New Uri("/" & lbi.Content & ".xaml", UriKind.Relative)
and it says on the report :
Requested operation is not available because the runtime library
function
'Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject'
is not defined.
NOTE :
when i am changing the ItemTap to this :
Private Sub ItemTap(ByRef sender As Object, e As GestureEventArgs)
this error is gone and appears another one :
Method 'Private Sub ItemTap(ByRef sender As Object, e As
System.Windows.Input.GestureEventArgs)' does not have a signature
compatible with delegate 'Delegate Sub EventHandler(Of
System.Windows.Input.GestureEventArgs)(sender As Object, e As
System.Windows.Input.GestureEventArgs)'.
at line : "AddHandler item.Tap, AddressOf ItemTap"
Any ideas why i have this one ??
thank you !
You're trying to combine two strings and an object and it can't do this.
I strongly suspect that lbi.Content (in the line that is erroring) is a TextBlock, so your code says "concatenate a string, a TextBlock and a string together".
I suspect that you want the text that is displayed in the TextBlock, so just cast it accordingly:
"/" & DirectCast(lbi.Content, TextBlock).Text & ".xaml"

how can i use ActiveDirectory

I have an active Directory (window) on the server ..and i want to connect it with my web pages..
this is my vb code:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Data
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.DirectoryServices ' cannot be found '
Imports System.Runtime.InteropServices
Imports System.Configuration
Imports System.Data.SqlClient
Partial Class Default3
Inherits System.Web.UI.Page
Public Function IsADUser(ByVal UserName As [String], ByVal Password As [String]) As [Boolean]
Dim entry As New DirectoryEntry()
entry.Username = UserName
entry.Password = Password
Dim searcher As New DirectorySearcher(entry)
searcher.Filter = "(objectclass=user)"
Dim Authentecated As [Boolean] = False
Try
searcher.FindOne()
Authentecated = True
Catch ex As COMException
Authentecated = False
End Try
Return (Authentecated)
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
The ASP.NET Membership supports Active Directory as well. Check it out:
http://msdn.microsoft.com/en-us/library/ms998360.aspx
To use Active Directory manually, you should add System.DirectoryServices.dll as a reference before.