I am trying to get a specific TestSuite using the TFS API for a TestPlan.
The TestSuite could exist anywhere within a TestSuite hierarchy, so, of course I could write a recursive function. I want something more efficient however.
Is there a method I am missing, or maybe a query that I could write?
If you already know the testSuiteId things are quite straightforward. You only need to know the name of your TeamProject teamProjectName:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
namespace GetTestSuite
{
class Program
{
static void Main()
{
int testSuiteId = 555;
const string teamProjectName = "myTeamProjectName";
var tpc =
TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
new Uri("http://tfsURI"));
var tstService = (ITestManagementService)tpc.GetService(typeof(ITestManagementService));
var tProject = tstService.GetTeamProject(teamProjectName);
var myTestSuite = tProject.TestSuites.Find(testSuiteId);
}
}
}
If you don't, you probably need to go for a solution similar to the one presented here (it's a S.Raiten post), where recursion does come into picture. Access to a testPlanId is assumed:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
namespace GetTestSuite
{
class Program
{
static void Main()
{
int testPlanId = 555;
const string teamProjectName = "myTeamProjectName";
var tpc =
TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
new Uri("http://tfsURI"));
var tstService = (ITestManagementService)tpc.GetService(typeof(ITestManagementService));
var tProject = tstService.GetTeamProject(teamProjectName);
var myTestPlan = tProject.TestPlans.Find(testPlanId);
GetPlanSuites(myTestPlan.RootSuite.Entries);
}
public static void GetPlanSuites(ITestSuiteEntryCollection suites)
{
foreach (ITestSuiteEntry suiteEntry in suites)
{
Console.WriteLine(suiteEntry.Id);
var suite = suiteEntry.TestSuite as IStaticTestSuite;
if (suite != null)
{
if (suite.Entries.Count > 0)
GetPlanSuites(suite.Entries);
}
}
}
}
}
Related
My codes:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Bolt;
using UdpKit;
//using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class ListOfIntToken : IProtocolToken
{
public List<int> intList;
public int byteArraySize;
public void Read(UdpPacket packet)
{
byteArraySize = packet.ReadInt();
var objectBytes = packet.ReadByteArray(byteArraySize);
var mStream = new MemoryStream();
var binFormatter = new BinaryFormatter();
mStream.Write(objectBytes, 0, objectBytes.Length);
mStream.Position = 0;
intList = binFormatter.Deserialize(mStream) as List<int>;
}
public void Write(UdpPacket packet)
{
var binFormatter = new BinaryFormatter();
var mStream = new MemoryStream();
binFormatter.Serialize(mStream, intList);
//byte[] bytes = userId.Select(x => (byte)x).ToArray();
var byteArray = mStream.ToArray();
byteArraySize = byteArray.Length;
packet.WriteInt(byteArraySize);
packet.WriteByteArray(byteArray);
}
}
I have two clients running A and B. A is server. Both are sending the event with this token but with different data for testing. In Write method I print the byteArraySize out, and when the data are received on server I print them out too. The byteArraySize for A's data is 0, and the time it's printed is before the printing line inWrite method, where the size was 221. However for B's data the size was correct. What may causes this problem?
Final solution:
public void Read(UdpPacket packet)
{
intList.Clear();
if (packet.ReadBool()) // check if we have data to read
{
var total = packet.ReadInt();
for (int i = 0; i < total; i++)
{
intList.Add(packet.ReadInt());
}
}
}
public void Write(UdpPacket packet)
{
var total = intList.Count;
if (packet.WriteBool(total > 0)) // Write bool to signal we have some data
{
packet.WriteInt(total);
foreach (var item in intList)
{
packet.WriteInt(item);
}
}
}
The weird bug is caused by assigning to a wrong variable. It's been corrected in the question.
I am generating an extent report in specflow, I have written the code and my test execute successfully and report generating but it displays only the feature name no steps name displayed in the report.
Please suggest me what mistake I am doing in the code.
I am attaching a screenshot of my generated report, When I go to report dashboard it displays the number of steps there.
using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using AventStack.ExtentReports.Reporter.Configuration;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;
namespace Extent_Report
{
[Binding]
[TestFixture]
class Hooks
{
public static ExtentReports extent;
public static ExtentHtmlReporter htmlReporter;
public static ExtentTest test;
// public static object Theme { get; private set; }
static Hooks()
{
if (extent == null)
{
BasicSetUp();
}
}
[BeforeScenario]
public static void Setup()
{
BasePage.Intitialize();
BasePage.Navigate();
test = extent.CreateTest(ScenarioContext.Current.ScenarioInfo.Title);
}
[AfterScenario]
public void TearDown()
{
if (ScenarioContext.Current.TestError != null)
{
var error = ScenarioContext.Current.TestError;
var errormessage = "<pre>" + error.Message + "</pre>";
extent.AddTestRunnerLogs(errormessage);
test.Log(Status.Error, errormessage);
test.Fail(errormessage);
}
BasePage.Quit();
}
[OneTimeSetUp]
public static void BasicSetUp()
{
string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
// string pth = System.IO.Directory.GetCurrentDirectory();
string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
string projectPath = new Uri(actualPath).LocalPath;
Console.WriteLine(" -----------Project Path--------------------------------------");
Console.WriteLine(projectPath);
string reportPath = projectPath + "Reports\\TestExecutionRunReport.html";
// Console.WriteLine("Report Path is " + reportPath);
htmlReporter = new ExtentHtmlReporter(reportPath);
htmlReporter.Configuration().Theme = Theme.Dark;
htmlReporter.Configuration().DocumentTitle = "SpecFlow Test Resport Document";
htmlReporter.Configuration().ReportName = "Feature Run Results";
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
//extent.LoadConfig(projectPath + "Extent-Config.xml");
}
[AfterFeature()]
public static void EndReport()
{
extent.Flush();
}
}
}
Reference:
You need to use hook [After step] or [Before step] and add below content to it
test = test.info(ScenarioStepContext.Current.StepInfo.Text);
you can also manipulate and provide more information in it if required.
I have to write unit test case and increase the code coverage for a pre written controller.
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using System.Web.Mvc;
using TW.Data.Business;
using TW.Data.Service;
using TW.Web.Models;
using TW.Common.Utility;
namespace TW.Web.Controllers
{
[Authorize]
public class BillinInfoSearchController : Controller
{
private IBillinInfoSearch _IRepository;
private IResponseMessage _ServiceResponse;
public BillinInfoSearchController(IBillinInfoSearch irepository, IResponseMessage serviceresponse)
{
_IRepository = irepository;
_ServiceResponse = serviceresponse;
}
public ActionResult ActionMethod()
{
BillinInfoSearchViewModel viewModel = new BillinInfoSearchViewModel();
viewModel.Success = false;
try
{
if (!Sitecore.Context.PageMode.IsExperienceEditor)
{
//Getting Custom Properties
var userBillAccountNumber = Sitecore.Context.User.Profile.GetCustomProperty(UserProfileDetails.BillAccountNumber);
var userObjectIdentifier = Sitecore.Context.User.Profile.GetCustomProperty(UserProfileDetails.ObjectIdentifier);
if (!string.IsNullOrEmpty(userBillAccountNumber) && !string.IsNullOrEmpty(userObjectIdentifier))
{
viewModel.ModelList = new List<BillinInfoSearchModel>();
_ServiceResponse = _IRepository.SubmitModelDetails(userBillAccountNumber, userObjectIdentifier);
if (_ServiceResponse.Success && !string.IsNullOrEmpty(_ServiceResponse.Content) && _ServiceResponse.Content.Contains("Top_GUID")
&& !Sitecore.Context.PageMode.IsExperienceEditorEditing)
{
List<BillinInfoSearchModel> objectList = JsonConvert.DeserializeObject<List<BillinInfoSearchModel>>(_ServiceResponse.Content);
if (objectList.Count > 0)
{
viewModel.Success = true;
viewModel.ModelList = objectList;
}
}
}
}
}
catch (Exception ex)
{
Sitecore.Diagnostics.Log.Error(ex.Message, this);
}
return View("~/Views/OAM/BillinInfoSearchView.cshtml", viewModel);
}
}
}
I wrote one Unit test case and code coverage comes to 24%. If i divide the controller code into small piece of code & methods and then call those in Unit test class, coverage increasing to 65%,but code is deployed in UAT and dont want to update the deployed code.
Is there we can increasing the code coverage without modifying the existing controller
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using System.Web.Mvc;
using TW.Data.Business;
using TW.Data.Service;
using TW.Web.Controllers;
using TW.Common.Utility;
namespace TW.UnitTest.Controller
{
[TestClass]
public class BillinInfoSearchControllerTest
{
[TestMethod]
public void BillinInfoSearchControllerViewName()
{
IBillinInfoSearch _IRepository = Substitute.For<IBillinInfoSearch>();
IResponseMessage _ServiceResponse = Substitute.For<IResponseMessage>();
BillinInfoSearchController twLiveController = new BillinInfoSearchController(_IRepository, _ServiceResponse);
Sitecore.Context.User.Profile.SetCustomProperty(UserProfileDetails.BillAccountNumber, "102134");
Sitecore.Context.User.Profile.SetCustomProperty(UserProfileDetails.ObjectIdentifier, "ef84bc1c-825c-4d8c-9801-3c3fc511a40e");
ViewResult action = twLiveController.ActionMethod() as ViewResult;
Assert.AreEqual("~/Views/OAM/BillinInfoSearchView.cshtml", action.ViewName);
}
}
}
using System;
using Android.App;
using Android.Os;
using Android.Widget;
using Dot42;
using Dot42.Manifest;
using Android.Location;
[assembly:UsesPermission(Android.Manifest.Permission.ACCESS_COARSE_LOCATION)]
[assembly:UsesPermission(Android.Manifest.Permission.INTERNET)]
[assembly:UsesPermission(Android.Manifest.Permission.ACCESS_FINE_LOCATION)]
[assembly: Application("simplegps")]
namespace simplegps
{
[Activity]
public class MainActivity : Activity
{
private LocationManager service;
private bool enable;
private string provider;
protected override void OnCreate(Bundle savedInstance)
{
base.OnCreate(savedInstance);
SetContentView(R.Layouts.MainLayout);
var txtprovider= FindViewById <TextView>(R.Ids.txtprovider);
var gpsstatus= FindViewById <TextView>(R.Ids.gpsstatus);
var txtcity = FindViewById<TextView>(R.Ids.txtcity);
var txtlat = FindViewById<TextView>(R.Ids.txtlat);
var txtlon = FindViewById<TextView>(R.Ids.txtlon);
service=(LocationManager)GetSystemService(LOCATION_SERVICE);
enable=service.IsProviderEnabled(LocationManager.GPS_PROVIDER);
if(enable)
{
gpsstatus.Text="Gps enabled";
}
else
{
gpsstatus.Text="Gps not enabled";
return;
}
var criteria = new Criteria{Accuracy = Criteria.ACCURACY_FINE};
provider = service.GetBestProvider(criteria,false);
var location = service.GetLastKnownLocation(provider);
if(location !=null)
{
txtprovider.Text=provider;
var latitude = location.Latitude;
var longitude = location.Longitude;
txtlat.Text=latitude.ToString();
txtlon.Text=longitude.ToString();
}
else
{
txtprovider.Text="no location";
return;
}
if(Geocoder.IsPresent())
{
Android.Location.Geocoder geo;
Android.Location.Address adds;
adds=geo.GetFromLocation(location.GetLatitude(),location.GetLongitude(),1);
}
}
}
}
error message:
It shows error "Cannot implicitly convert type 'Java.Util.IList' to 'Android.Location.Address'. An explicit conversion exists (are you missing a cast?) (CS0266)"
This is the line that fails:
adds = geo.GetFromLocation(location.GetLatitude(), location.GetLongitude(), 1)
geo.GetFromLocation returns Java.Util.IList<Address>. adds is of type Address. Hence the compile error.
Use the index operator to access one of the Addresses.
EDIT
Also, you should initialize geo before using it:
Geocoder geo = new Geocoder(this, Locale.getDefault());
Finally, GetFromLocation may return null or an empty list, so check for both.
Below is the code from the DotNetNuke Sample module that gets a collection of items from the database that belong to a particular module. What I want is add a second parameter for it filter by. I'm guessing this has something to do with modifying the scope item.cs class but am not sure how exactly.
public IEnumerable<Item> GetItems(int moduleId)
{
IEnumerable<Item> t;
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<Item>();
t = rep.Get(moduleId);
}
return t;
}
Any ideas?
Another way to do it in DAL2 is using the .Find() method. This is good if you want to query on an indexed field in your table and you don't care about caching scope:
public IEnumerable<Item> GetItemByName(int moduleId, string itemname)
{
IEnumerable<Item> t;
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<Item>();
t = rep.Find("WHERE ModuleId = #0 AND ItemName LIKE #1", moduleId, itemname);
}
return t;
}
Here's some sample code from my SignalRChat module that uses DAL2 (http://signalrchat.codeplex.com/SourceControl/changeset/view/71473#1272188)
public IEnumerable<Message> GetRecentMessages(int moduleId, int hoursBackInTime, int maxRecords)
{
var messages = (from a in this.GetMessages(moduleId) where a.MessageDate.Subtract(DateTime.UtcNow).TotalHours <= hoursBackInTime select a).Take(maxRecords).Reverse();
return messages.Any() ? messages : null;
}
That is one approach, you can also use a SQL statement within the controller as well (http://signalrchat.codeplex.com/SourceControl/changeset/view/71473#1272186)
public ConnectionRecord GetConnectionRecordByConnectionId(string connectionId)
{
ConnectionRecord t;
using (IDataContext ctx = DataContext.Instance())
{
var connections = ctx.ExecuteQuery<ConnectionRecord>(CommandType.Text,
string.Format(
"select top 1 * from {0}{1}SignalRChat_ConnectionRecords where ConnectionId = '{2}'",
_databaseOwner,
_objectQualifier,
connectionId)).ToList();
if (connections.Any())
{
t = connections[0];
}
else
return null;
}
return t;
}