Posts

Showing posts from 2015

Upgrading your ASP.NET 5 project from Beta 7 to Beta 8

Microsoft just released ASP.NET 5 and Entity Framework Beta 8. There were some breaking changes which require some changes in existing code. All changes can be found here: Announcing Availability of ASP.NET 5 Beta8 As with every upgrade you should change the -beta7 to -beta8 in the global.json and in all package.json files. Below I address the things I found which need to be corrected: Package.json Remove these dependencies: "Microsoft.AspNet.Server.IIS": "1.0.0-beta7" "Microsoft.AspNet.Server.WebListener": "1.0.0-beta7" and replace them with: "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8" "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8" Finally add this one: "Microsoft.Framework.Logging.Debug" : "1.0.0-beta8" Now change the web command "web": "Microsoft.AspNet.Hosting --config hosting.ini" to "web": "Microsoft.AspNet.S

Mocking EF DataContext with Moq

So I wanted to mock the interface I use as base for my data context in my unit tests. Mocking the interface itself is pretty easy, but I wanted to check if the properties of type DbSet have changed correctly. So, all we need to do is mock the methods of the DbSet we are using, e.g. Add() and AddRange(), and use a callback to send the value of the method calls to a List . As you can see, the method calls to a DbSet can easily be captured and send to another List which we can use for our asserts.

Creating a basic MVC 6 web application with Entity Framework 7 and xUnit - Part 2

Image
In this blog post we will connect to an actual database, create the tables using the code-first approach and add some initial data. Be aware that migrations seem to be a bit buggy at the moment, but my solution was (at least for me) the most stable one. You can clone the repository with this sample from Github . 1. Creating a database First, open the sql server object explorer (in the V iew  menu). I use the default MSSQLLocalDB for this example, but you can use any running SQLServer. Now add a new database to this SQL Server. Specify a database name and the location where to put the database file. Finally, we need the connection string for this database. Get to the properties of the newly created database and copy the connection string. 2. Necessary changes before the migrations Before we can run any migration, we have to set up some things. Create a Config.json in the Sample1 project and add your connection string. Attention: you have to escape the backsla

Creating a generic Clone() method for dictionaries

I wanted to create a Clone method for dictionaries which returns the same type as the Dictionary on which the method was called: This would be quite easy if we would do an extension method for every type of dictionary, but I wanted to do this for all IDictionary implementations. Here is my solution: Since cloning works by creating a new instance with the source dictionary as constructor parameter, we have to use Activator.CreateInstance to create a new instance.

Creating a basic MVC 6 web application with Entity Framework 7 and xUnit - Part 1

Image
In my first post I'm showing you how to set up a basic MVC 6 web application with Entity Framework 7. Before we do any controllers, or creating any databases, we use xUnit and moq for creating a mock database context and testing our service. You can clone the repository with this sample from  Github . 1. Creating the projects Open Visual Studio 2015 RC and select New project . Make sure you choose .NET Framework 4.6. Now create an empty ASP.NET 5 project. Now create two projects of type Class Library, Sample1Data and Sample1DataTests : You should now have 3 projects in your solution: Next we need to install MVC 6, Entity Framework 7 and xUnit. To do this, we don't use the NuGet UI. It's easier to edit the project.json file of each project and adding the references there. Enjoy the Intellisense ;). Begin with the Sample1 project. Make sure you dependencies section looks like this: As you can see, we already added a dependency to our Sample1Data pro

Impressum

Datenschutzerklärung Diese Datenschutzerklärung klärt Sie über die Art, den Umfang und Zweck der Verarbeitung von personenbezogenen Daten (nachfolgend kurz „Daten“) innerhalb unseres Onlineangebotes und der mit ihm verbundenen Webseiten, Funktionen und Inhalte sowie externen Onlinepräsenzen, wie z.B. unser Social Media Profile auf (nachfolgend gemeinsam bezeichnet als „Onlineangebot“). Im Hinblick auf die verwendeten Begrifflichkeiten, wie z.B. „Verarbeitung“ oder „Verantwortlicher“ verweisen wir auf die Definitionen im Art. 4 der Datenschutzgrundverordnung (DSGVO). Verantwortlicher Jan-Patrick Ahnen Lisztstraße 28 67574 Osthofen https://blog.jpahnen.com/2018/05/impressum.html Arten der verarbeiteten Daten: - Bestandsdaten (z.B., Namen, Adressen). - Kontaktdaten (z.B., E-Mail, Telefonnummern). - Inhaltsdaten (z.B., Texteingaben, Fotografien, Videos). - Nutzungsdaten (z.B., besuchte Webseiten, Interesse an Inhalten, Zugriffszeiten). - Meta-/Kommunikationsdaten (z.B., Geräte-Inf