Introduction In [my previous post][1] I made a Plantsmodule which had 2 routes. One of those routes had a problem when tried to put a string in the parameter and that was less than optimal. It was time for tests to make it easier on myself to test these kinds of things. The module So here is my module. Imports WebApplication2.Model Imports Nancy Public Class PlantsModule Inherits NancyModule Public Sub New() MyBase.Get("/plants") = Function(parameters) Return View(New PlantsModel() With {.Plants = New List(Of PlantModel) From {New PlantModel() With {.Id = 2, .Name = "test"}}}) End Function MyBase.Get("/plants/{Id}") = Function(parameters) If parameters.id = 1 Then Return View(New PlantModel() With {.Id = 1, .Name = "test"}) Else Return View(New PlantModel() With {.Id = 2, .Name = "test"}) End If End Function End Sub End Class``` This one throws an exception when you enter abc or any other bad value. ## The tests To begin with you should nuget the Nancy.Testing package. Then you can use the Browser. For our purpose it would look something like this. ```vbnet Private _browser As Browser <SetUp()> Public Sub FixtureSetup() Dim configuration = A.Fake(Of IRazorConfiguration)() Dim bootstrapper = New ConfigurableBootstrapper(Sub(config) config.Module(Of PlantsModule)() config.ViewEngine(New RazorViewEngine(configuration)) End Sub) _browser = New Browser(bootstrapper) End Sub``` So we tell it what Module to use and we tell it what Engine to use. We also use FakeItEasy to make a mock for our RazorConfiguration. For the next part I got some help from [this blogpost by Jef Claes][2]. if you leave out the Engine you will get this error. > System.Exception : ConfigurableBootstrapper Exception > —-> Nancy.RequestExecutionException : Oh noes! > —-> Nancy.ViewEngines.ViewNotFoundException : Unable to locate view ‘Plants’ > Currently available view engine extensions: sshtml,html,htm > Locations inspected: ,,,,views/Plants/Plants,Plants/Plants,views/Plants,Plants > Root path: E:UserschristiaanAppDataLocalNCrunch708461WebApplication2bin Do you notice how it does not mention cshtml or vbhtml in view engine extensions? That is solved by telling it what engine to use. In theory that should work but you will get this error when you try it. > System.Exception : ConfigurableBootstrapper Exception > —-> Nancy.RequestExecutionException : Oh noes! > —-> Nancy.ViewEngines.ViewNotFoundException : Unable to locate view ‘Plants’ > Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml > Locations inspected: ,,,,views/Plants/Plants,Plants/Plants,views/Plants,Plants > Root path: E:UserschristiaanAppDataLocalNCrunch708461WebApplication2bin That is solved by the RootPathProvider we find in the blogpost by Jef Claes. In VB.Net that would look like this. ```vbnet Imports System.IO Imports Nancy Public Class RootPathProvider Implements IRootPathProvider Private Shared _cachedRootPath As String Public Function GetRootPath() As String Implements IRootPathProvider.GetRootPath If Not String.IsNullOrEmpty(_cachedRootPath) Then Return _cachedRootPath Dim currentDirectory = New DirectoryInfo(Environment.CurrentDirectory) Dim rootPathFound = False While Not rootPathFound Dim directoriesContainingViewFolder = currentDirectory.GetDirectories("Views", SearchOption.AllDirectories) If directoriesContainingViewFolder.Any() Then _cachedRootPath = directoriesContainingViewFolder.First().FullName rootPathFound = True End If currentDirectory = currentDirectory.Parent End While Return _cachedRootPath End Function Public Function Equals1(obj As Object) As Boolean Implements IHideObjectMembers.Equals End Function Public Function GetHashCode1() As Integer Implements IHideObjectMembers.GetHashCode End Function Public Function GetType1() As Type Implements IHideObjectMembers.GetType End Function Public Function ToString1() As String Implements IHideObjectMembers.ToString End Function End Class``` The above presumes your views are in a Views subfolder. Which they are of course. And now we can start writing tests. ```vbnet <Test> Public Sub IfPlantsRouteReturnsStatusCodeOk() Dim result = _browser.Get("/plants", Sub(x) x.HttpRequest() End Sub) Assert.AreEqual(HttpStatusCode.OK, result.StatusCode) End Sub <Test> Public Sub IfPlantWithId1RouteReturnsStatusCodeOk() Dim result = _browser.Get("/plants/1", Sub(x) x.HttpRequest() End Sub) Assert.AreEqual(HttpStatusCode.OK, result.StatusCode) End Sub <Test> Public Sub IfPlantWithIdabcRouteReturnsStatusCodeOk() Dim result = _browser.Get("/plants/abc", Sub(x) x.HttpRequest() End Sub) Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode) End Sub``` I just want to check if I get an ok code when it works and a not found when I do plants/abc But the last test fails. With this exception. ```vbnet System.Exception : ConfigurableBootstrapper Exception ----> Nancy.RequestExecutionException : Oh noes! ----> System.InvalidCastException : Conversion from string "abc" to type 'Double' is not valid. ----> System.FormatException : Input string was not in a correct format. Time to change our Module. And do the simplest thing to make our test pass.
This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.
This is day thirteen of the SQL Advent 2012 series of blog posts. Today we are going to look at servers where everything is installed and enabled. Before we start this post let’s look back in time a little. Before SQL Server 2005 came out when you installed SQL Server pretty much everything was turned on by default. This of course widened the attack vector against the database servers. With SQL Server 2005 pretty much everything is turned off and you have to turn the features on if you want to use them. Now sometimes some admins will just turn everything on because that way they don’t have to deal with this later, this are also the same kind of people who insist that the account needs to be db_owner otherwise their code won’t work.
Last night I had the pleasure of presenting “The What, Why, and How of Filegroups” for the East Iowa I-380 SQL Server user group. Thanks for having me! My presentation materials are available [here][2]. During the presentation, I show the DBCC CHECKFILEGROUP command. An attendee asked if running this command instead of a full DBCC CHECKDB would reduce the size of the snapshot created. I asked my good friend Erin Stellato ([blog][3] | [twitter][4]), and she gave me this excellent information:
This is day twelve of the SQL Advent 2012 series of blog posts. Today we are going to look at SQL Server proactive notifications. In the SQL Server Maintenance post from yesterday I touched upon proactive notifications a little, today I want to dive a little deeper into this subject. The last thing you want as a DBA is to hear any of the following things from the end users The transaction log is full The database is very slow The latest backup we have is 9 days old The table that was created has 2 extra columns this morning Everything is locked up can’t get any results back from a query Deadlocks are occurring What you really want to have at your shop is a tool like Quest Foglight, Confio Ignite, Red Gate SQL Monitor or similar. The benefit of these tools is that there is a central location where you can look at all the alerts at a glance. You get a lot of stuff out of the box and all you have to do is tell it what server to start monitoring. I would suggest to start using the trial version to see if it is something that would be beneficial for your organization.
Introduction Yesterday I [started using Nancy,][1] and I used the SuperSimpleViewEngine but I was told to use the razor view engine instead. And because I’m a good boy I did that. Getting it to work First thing to do is to install the Nancy.Viewengines.Razor package from nuget. This of course downloads the needed assemblies and adapts your webconfig. And it makes a mistake when adapting the webconfig. Your webconfig will look like this when it is done.
This is day eleven of the SQL Advent 2012 series of blog posts. Today we are going to look at cursors and loops. Why do we hate those poor cursors? Let’s first see why people tend to use cursors. Let’s say you come from a procedural language and this is the first time you are using SQL. In the procedural language you know how to traverse a list, you of course will look for something that is similar in SQL……..bingo!!! you found it…the almighty cursor….the crusher of allmost all SQL Server performance. You start using it, your code works, you are happy, life is good. Now a team member tells you that the cursor is evil and should never ever be used. You are confused, if a cursor is never to be used then why is it part of the language? Well you might say the same for the goto statement, this exists in SQL however Edsger Dijkstra’s letter Go To Statement Considered Harmful was published in the March 1968 Communications of the ACM.
For some time I wanted to document the possibilities of the SQL Server Database Project and how developers and DBA’s can benefit from it. Problem Statement Many companies I’ve worked for struggle with their database lifecycle management: Production databases are copied to Test, Staging, UAT… environments by the DBA’s with production (sensitive) data DBA’s spend too much time doing the copy operations Backup chains are broken because of the lack of use of the WITH COPY_ONLY option Changes are made by the DBA executing individual scripts, sometimes breaking because the development database and production database were out of sync. Bugs are “Emergency” fixed in the production database so the schemas of the development and production database are out of sync … Possible solution
This month’s T-SQL Tuesday is hosted by Sebastian Meine (blog | twitter) and the topic is joins. He has a whole month worth of topics about joins: A Join A Day – Introduction. I thought I’d write about a question I get often from Developers and some DBAs. This may seem like a simple and basic task but it is a common question asked, “How do I update a column based on a query that has joins in it?”
Introduction A few hours ago I started [a website in Nancy][1]. Now I want to show data I have in my webpage. And here the docs were not all that helpfull. But I made it. The Model First of all I need a Model. Namespace Model Public Class PlantsModel Public Property Id As Integer Public Property Name As String Public Property LatinName As String End Class End Namespace``` And I put that in a Model folder. I ended with Model since that is the convention but not really needed in all cases. ## The View Time to move on to more exiting things. I created a Plants.html file. ```html <!DOCTYPE html> <html> <head> <title>NancyFX</title> </head> <body> <h1>Plants</h1> <div id="plants"> <p>@Model.Id</p> <p>@Model.Name</p> </div> </body> </html> ``` I used the [SuperSimpleViewEngine][2] for this. As you see I just add the @Model. and then the name of the property I want. Simples. Now I just need to tell my controller what to do. ## The Controller I guess we can call our module our controller. ```vbnet Imports WebApplication2.Model Imports Nancy Public Class PlantsModule Inherits NancyModule Public Sub New() MyBase.Get("/plants") = Function(parameters) Return View(New PlantsModel() With {.Id = 2, .Name = "test"}) End Function End Sub End Class``` So the url http://localhost/plants will take you to the page Plants.htmland will inject the PlantsModel I just created in there. By convention the fact that you inject a PlanstModel in there informs Nancy that you want to use the Plant.html view. You could have written this instead. ```vbnet Imports WebApplication2.Model Imports Nancy Public Class PlantsModule Inherits NancyModule Public Sub New() MyBase.Get("/plants") = Function(parameters) Return View("Plants.html", New PlantsModel() With {.Id = 2, .Name = "test"}) End Function End Sub End Class``` Or any other html. And that gives us this amazing page. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/nancy/nancy5.png?mtime=1355234722"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/nancy/nancy5.png?mtime=1355234722" width="230" height="243" /></a> </div> ## Conclusion Slightly harder than it should have been because I could not find the correct docs that explained this simply. But I got it working anyway. [1]: /index.php/WebDev/ServerProgramming/ASPNET/nancy-and-vb-net [2]: https://github.com/NancyFx/Nancy/wiki/View-engines
Introduction After having tried out [Servicestack][1] it is time to try [Nancy][2]. Nancy is a lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono. The goal of the framework is to stay out of the way as much as possible and provide a super-duper-happy-path to all interactions. Nancy has some [nice docs][3] and I like that. And Nancy has a nice ecosystem and dedicated masters. Hello world Hello world should be easy enough. Just create an empty asp.net project and then add the nuget package. And some code.