When compiling Specflow project - generation error reported - specflow

I am creating a new Specflow project in VS2017. I have added 1 rule in the features file and generated the initial steps code. However, when I attempt to build the project I get the following 2 errors.
(1) CS1029 #error: 'Generation error: Object reference not set to an instance of an object.'
(2) Custom tool error: Generation error: Object reference not set to an instance of an object.
Feature file contains,
Feature: Change_Theme_Change_Scheme
#Change_Theme_Change_Scheme
Scenario: Verfy change of scheme
Given I log into Admin site
And I navigate to Colour Scheme page
And I select the Kumho theme
When I click the Save Theme button
Then Check website main menu background is Red
Steps file contains,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
namespace Tyres_and_Service_Tester.Steps
{
[Binding]
public sealed class Change_Theme_Change_Scheme
{
[Given(#"I log into Admin site")]
public void GivenILogIntoAdminSite()
{
ScenarioContext.Current.Pending();
}
[Given(#"I navigate to Colour Scheme page")]
public void GivenINavigateToColourSchemePage()
{
ScenarioContext.Current.Pending();
}
[Given(#"I select the Kumho theme")]
public void GivenISelectTheKumhoTheme()
{
ScenarioContext.Current.Pending();
}
[When(#"I click the Save Theme button")]
public void WhenIClickTheSaveThemeButton()
{
ScenarioContext.Current.Pending();
}
[Then(#"Check website main menu background is Red")]
public void ThenCheckWebsiteMainMenuBackgroundIsRed()
{
ScenarioContext.Current.Pending();
}
}
}
Image of project references
I've not come across this before when building Specflow projects with earlier versions of VS, and cannot figure out what I've done differently
Many thanks for any help. Tony

Thank you for all your responses. I decided to start from scratch again adding the Specflow packages to VS, and recreating the features, steps etc. As you might of guessed it worked this time - so I'm at a loss what might of been going on. Anyway this question can be closed.

Related

Error when using MvxAppCompatActivity

I am writing an application with Xamarin.Android with MvvmCross. I want my Activity to inherit from MvxAppCompatActivity so that I can use fragments. Here is my base class:
public class BaseActivity<TViewModel> : MvxAppCompatActivity<TViewModel> where TViewModel : MvxViewModel
{
public new TViewModel ViewModel
{
get { return base.ViewModel; }
set { base.ViewModel = value; }
}
}
I get this error on the OnCreate of my Activity:
Failed resolution of: Landroid/support/v7/appcompat/R$drawable; Didn't
find class "android.support.v7.appcompat.R$drawable" on path:
DexPathList...
But if I change MvxAppCompatActivity to MvxActivity it works fine...why?
I downloaded your solution and tried to build the Android project. It fails with 18 occurrences of the same error:
error: No resource identifier found for attribute 'loginButtonBackgroundColor' in package ...
So after a little inspection of your solution, I did the following steps to solve your issue:
1) In login_screen.axml I saw you had this line:
xmlns:[YOURNAMESPACE]="http://schemas.android.com/apk/res/[YOUR PACKAGE]"
Which is unnecessary. After removing it, and changing the lines [YOURNAMESPACE]:loginButtonBackgroundColor=... to local:loginButtonBackgroundColor=... the build succeeds.
2) I saw some layout files are located inside the /drawable folder (button_round_corner.xml, input_box.xml and login_button.xml). I moved them to the /layout folder and fixed the issues the change produced (only two).
3) Made Setup class inherit from MvxAppCompatSetup.
4) Added a RegisterAttribute over the LoginButton control. So the class definition looks like this:
using Android.Runtime;
...
namespace Xxx.Droid.Components
{
[Register(nameof(LoginButton))]
public class LoginButton : FrameLayout, IMvxNotifyPropertyChanged
{
...
}
}
And that's it! Probably (2) was not necessary, but leaving it here just in case.
It could be several things but it is probably the lack of some android support packages. Mainly the lack of Xamarin.Android.Support.Design gives that error. So check if you have that added and if not add it and it should solve your problem.
If it doesn't it's highly likely you lack some other android support packages

TFS Build 2013 - Variable scope and custom activities

I was trying to do something similar to the stackoverflow article referenced below and am finding I can't set values in the code activity. I seem to be able to read values OK. I suspect this has something to do with the scope of these. In the stackoverflow article the code implied that the variable was set for the loop,
I am after guidance on how to set these correctly or a way for my codeactivity to flag to exit the external DoWhile loop ?
Refs
StackOverflow Article
Code Activity article
OK here is the missing story and is not in the MS doco that I have found..
e.g. https://msdn.microsoft.com/en-us/library/dd647551(v=vs.120).aspx
Although MS document In, InOut, Out args their scope is not shared... i.e.
WRONG View of the world
XAML argument like MyBoolInOut Inout is the same argument that the C# code is using , e.g.
public InOutArgument MyBoolInOut { get; set; }
thus you only need to change values in C# code to change the values in the TFS XAML
Correct view of this handling
The custom code activity variables are visible in the XAML BUT are different from the XAML arguments. i.e.
as below, your C# codeactivity args have to be manually linked to the XAML args
So even though XAML has arguments and C# have arguments, these are separate.
This is an area MS could greatly improve their doco in.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.TeamFoundation.Build.Workflow.Activities;
namespace SampleActivityLibrary
{
[BuildActivity(HostEnvironmentOption.All)]
// Sample Acitivty that will Flip a bool from True to False or from False to True
public sealed class SampleFlipInOutBoolean : CodeActivity<Boolean>
{
public InOutArgument<Boolean> MyBoolInOut { get; set; }
protected override Boolean Execute(CodeActivityContext context)
{
Boolean MyBool = context.GetValue(MyBoolInOut);
context.TrackBuildWarning("SampleFlipInOutBoolean: In Value of Bool: " + MyBool.ToString(), BuildMessageImportance.High);
MyBoolInOut.Set(context, !MyBool);
MyBool = context.GetValue(MyBoolInOut);
context.TrackBuildWarning("SampleFlipInOutBoolean: Out Value of Bool: " + MyBool.ToString(), BuildMessageImportance.High);
return MyBool;
}
}
}

Trigger a build only when check in to specific folder and subs - Continuous Integration TFS

I have a TFS build setup using Continuous Integration. Everything works correctly.
I'm trying to limit the check-ins that trigger a build to a specific folder (and subs).
Currently, any check-in to the Source Control folder set in my definition causes the project to build, but I would like the build to be triggered only when code is checked-in to one of the sub directories (and it's subs) in the Source Control folder.
Does anyone have any ideas? I have gone into the Default build template to try to make changes, but no luck so far.
Unfortunately TFS uses the Workspace Mapping defined in the Build Definition for two purposes: Define what files get downloaded to the build server, and define which files/folders trigger CI/Gated builds.
For the vast majority of cases these are the same thing, so it works fine. If that doesn't work for you, there is a way to workaround it, but it's not pretty.
You can setup the Workspace Mapping to specify which files/folders should trigger the CI build. Then customize the build workflow to not use the Workspace Mapping when downloading code, but instead you can either hardcode the path(s) to download into the workflow, or you can expose some custom Build Parameters that get set in the Build Def to specify the folders to download.
I have successfully worked around this limitation as follows.
The default TFS build process template uses the built-in "CreateWorkspace" activity, which takes the mappings in the build definition and creates the corresponding TFS workspace. It doesn't look like there is any way to customize this activity directly.
However, it is possible to add additional activities into the process, immediately after the "CreateWorkspace" activity, which injects additional working folder mappings to the source control workspace. These additional mappings will cause source to be retrieved from TFS and be available during the build without themselves triggering any CI builds.
The key is creating a new custom build workflow activity that is able to add a mapping to the existing workspace. I chose to extend the base activity in http://tfsbuildextensions.codeplex.com/, as follows:
using System;
using System.Activities;
using System.ComponentModel;
using System.Text;
using System.Text.RegularExpressions;
using global::TfsBuildExtensions.Activities;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
[Description("Adds a mapping to the workspace.")]
[BuildActivity(HostEnvironmentOption.All)]
public class AddWorkspaceMapping : BaseCodeActivity
{
public InArgument<Workspace> Workspace { get; set; }
public InArgument<string> ServerItem { get; set; }
public InArgument<string> LocalItem { get; set; }
public InArgument<string> BuildDirectory { get; set; }
public InArgument<string> SourcesDirectory { get; set; }
protected override void InternalExecute()
{
var ctx = this.ActivityContext;
Workspace ws = this.Workspace.Get(ctx);
string serverItem = this.ServerItem.Get(ctx);
string localItem = this.LocalItem.Get(ctx);
if (!string.IsNullOrWhiteSpace(serverItem))
{
localItem = ExpandEnvironmentVariables(localItem);
ws.Map(serverItem, localItem);
}
}
// Similar to the internal implementation of Microsoft.TeamFoundation.Build.Common.BuildCommonUtil.ExpandEnvironmentVariables()
internal string ExpandEnvironmentVariables(string inputStr)
{
...
}
}
The solution I use is very similar to the above. When creating the mapping in the build definition, I cloak folders I do not want to trigger CI builds. Then in the workflow I add a custom activity to remove the cloaks right after the CreateWorkspace action. Removing the cloaks allows any source in those folders to be available for the build.
This allows everything to be managed from the build definition and does not require changing the workflow if there is a need to modify which folders should trigger a CI build, or which folders need to be available to build.
This may work better for you, depending on the complexity of your workspace mappings.
The code for the activity is as follows:
using System.Activities;
using System.Linq;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
[BuildActivity(HostEnvironmentOption.All)]
public sealed class RemoveCloaksFromWorkspace : CodeActivity
{
[RequiredArgument]
public InArgument<Workspace> Workspace { get; set; }
protected override void Execute(CodeActivityContext context)
{
var ws = this.Workspace.Get(context);
ws.Folders.Where(f => f.IsCloaked).ToList().ForEach(f => ws.DeleteMapping(f));
}
}

Orchard - Can't find the Resource defined in ResourceManifest.cs

I have a custom there, where I try to require some of my css and js files via the ResourceManifest.cs file - I keep into running a quite weird issue tough.
I get the following error:
a 'script' named 'FoundationScript' could not be found
This is my ResourceManifest.cs:
using Orchard.UI.Resources;
namespace Themes.TestTheme
{
public class ResourceManifest : IResourceManifestProvider
{
public void BuildManifest(ResourceManifestBuilder builder)
{
var manifest = builder.Add();
manifest.DefineStyle("Foundation").SetUrl("foundation.min.css");
manifest.DefineScript("FoundationScript").SetUrl("foundation.min.js");
}
}
}
In the Layout.cshtml, I have following:
#{
Script.Require("ShapesBase");
Script.Require("FoundationScript");
Style.Include("site.css");
Style.Require("Foundation");
}
What am I missing here?
The issue here is, that the project Themes has a problem with the dynamic compile mechanism of Orchard (i don't know what is wrong exactly) because it resides in folder Themes. Even if you define a class inside the Themes assembly, it will result in an error telling you there is no such class in that assembly.
solution :
Try re-generating your theme with /CreateProject:true and /IncludeInSolution:true parameters as follows:
codegen theme TestTheme /CreateProject:true /IncludeInSolution:true /BasedOn :TheThemeMachine
It will create your theme in a separate project and orchard will pick your registered ResourceManifest.
Hope this helps.

Avoiding missing views in ASP.NET MVC

When testing an ASP.NET MVC 2 application I hit a problem when a view could not be located.
Looking at the code I realised that the aspx file for the view had not been added to the source control repository. On this project that's quite easy to do as we use StarTeam for source control and it doesn't show new folders when checking in. This view was for a new controller and so a new folder was created for it and it was therefore missed.
Our build server (using Hudson/MSBuild) didn't pick up on this, as the code still builds fine with the aspx file missing. Our controller unit tests test the ActionResults which obviously still pass without the view there.
This got picked up in system testing but how can I catch this earlier (ideally on the build server).
Thanks in advance
You can write unit tests that test the actual view, and then if the unit test doesn't pass on the build server, you know you have a problem. To do this, you can use a framework such as this:
http://blog.stevensanderson.com/2009/06/11/integration-testing-your-aspnet-mvc-application/
With this you can write unit tests such as this (from the post)
[Test]
public void Root_Url_Renders_Index_View()
{
appHost.SimulateBrowsingSession(browsingSession => {
// Request the root URL
RequestResult result = browsingSession.ProcessRequest("/");
// You can make assertions about the ActionResult...
var viewResult = (ViewResult) result.ActionExecutedContext.Result;
Assert.AreEqual("Index", viewResult.ViewName);
Assert.AreEqual("Welcome to ASP.NET MVC!", viewResult.ViewData["Message"]);
// ... or you can make assertions about the rendered HTML
Assert.IsTrue(result.ResponseText.Contains("<!DOCTYPE html"));
});
}
What version of StarTeam are you running? In StarTeam 2008 (not sure when this feature was first added) within a selected project/view, you can select from the menu Folder Tree->Show Not-In-View Folders. This will show folders you have on local disk that have not been added to the project (they will appear with the folder icon colored white).
This is an old question, but if anyone still looking for this you ought to try SpecsFor.Mvc by Matt Honeycutt.
Not only it can be used to make sure the Views are properly included/added in the source control, it can even do integration test to make sure those Views are valid.
Link to its website: http://specsfor.com/SpecsForMvc/default.cshtml
Link to the nuget package: https://www.nuget.org/packages/SpecsFor.Mvc/
Link to github: https://github.com/MattHoneycutt/SpecsFor
Here is a code snippet taken from the website showing how to use it.
public class UserRegistrationSpecs
{
public class when_a_new_user_registers : SpecsFor<MvcWebApp>
{
protected override void Given()
{
SUT.NavigateTo<AccountController>(c => c.Register());
}
protected override void When()
{
SUT.FindFormFor<RegisterModel>()
.Field(m => m.Email).SetValueTo("test#user.com")
.Field(m => m.UserName).SetValueTo("Test User")
.Field(m => m.Password).SetValueTo("P#ssword!")
.Field(m => m.ConfirmPassword).SetValueTo("P#ssword!")
.Submit();
}
[Test]
public void then_it_redirects_to_the_home_page()
{
SUT.Route.ShouldMapTo<HomeController>(c => c.Index());
}
[Test]
public void then_it_sends_the_user_an_email()
{
SUT.Mailbox().MailMessages.Count().ShouldEqual(1);
}
[Test]
public void then_it_sends_to_the_right_address()
{
SUT.Mailbox().MailMessages[0].To[0].Address.ShouldEqual("test#user.com");
}
[Test]
public void then_it_comes_from_the_expected_address()
{
SUT.Mailbox().MailMessages[0].From.Address.ShouldEqual("registration#specsfor.com");
}
}
}

Resources