I would like to mock a C# method that returns an Azure.AsyncPageable.
This class has only protected constructors, so I cannot instantiate it directly. Is there any way to create an instance of this class from some other collection, such as an IAsyncEnumerable or just a List?
You can create Page objects using Page<T>.FromValues.
Then, create a AsyncPageable<T> using AsyncPageable<T>.FromPages.
Example:
var page = Page<TableEntity>.FromValues(new List<TableEntity>
{
new TableEntity("1a", "2a"),
new TableEntity("1", "2b")
}, continuationToken: null, new Mock<Response>().Object);
var pages = AsyncPageable<TableEntity>.FromPages(new[] { page });
I'm Trying to create new instance of a DotNetBrowser and assign it to my panel inside windows forms.
Based on DotNetBrowser start guide, to create new instance of browser (that have its own cache, etc) I need to do following:
BrowserContextParams params1 = new BrowserContextParams("C:\\my-data1");
BrowserContext context1 = new BrowserContext(params1);
Browser browser1 = BrowserFactory.Create(context1);
My question is, what do I do with this browser now?
I want to asign it to my browserpanel like this
browserpanel.Controls.Add(browser1);
But this will not work because I need to have object of a class
WinFormsBrowserView to assign it to browserpanel. And If I create object of a type WinFormsBrowserView, I cant customize it as documentation explains.
And the Browser inside newly constructed WinFormsBrowserView is readonly, so i cant assign this browser to it.
Found solution:
BrowserContextParams params1 = new BrowserContextParams("C:\\my-data1");
context1 = new BrowserContext(params1);
browser1 = BrowserFactory.Create(context1);
WinFormsBrowserView browserview = new WinFormsBrowserView(browser1);
private AdvancedColorInfo advancedColorInfo = new AdvancedColorInfo();
I have tried the above code, but get this error:
“AdvancedColorInfo doesn't contain a constructor that takes 0
arguments.”
I am trying to use the method IsHdrMetadataFormatCurrentlySupported, so I need to create an instance of the AdvancedColorInfo class.
I tried changing the UWP Windows version that is mentioned in the documentation but no luck.
How do I get an instance of AdvancedColorInfo?
To get an AdvancedColorInfo you don't new them up directly.
Instead, you need to:
var displayInfo = DisplayInformation.GetForCurrentView();
var colorInfo = displayInfo.GetAdvancedColorInfo();
var isHDRSupported = colorInfo.IsHdrMetadataFormatCurrentlySupported(yourFormatPassInHere);
The first method call is a static call to get the DisplayInformation. The second is to get the AdvancedColorInfo from the DisplayInformation.
I have a very weird issue and I am clueless as to what is causing this behaviour.
I will provide the relevant code of two classes, to keep this short.
Class A has a method that gets an xml document and puts that in an XDocument object, it uses a method from class B for this. Then it uses a different but similar method from class B to add some additional xml to the XDocument.
For some reason, when I run the test cases, the second method from Class B is never entered. Instead, it gives back null.
Here is the code:
First call to a method in class B, from class A
// Get view (xml) for current supplier
XDocument navigationView = ProductBUS.GetProductNavigationXDocument(suppID, viewName, selectedProductNavigationView);
Second call to a method in class B, from class A (this is the faulty one)
if (true)
{
navigationView = ProductBUS.AddOptionsToNavigationMenu(navigationView);
}
(The if(true) is placeholder code, will be changed in the future to a boolean value. This value needs to come from the DB, which is empty at this point.)
The methods in class B, 1 and 2 respectively.
public XDocument GetProductNavigationXDocument(Guid supplierID, String viewName, string selectedProductNavigationView)
{
// TODO : implementing full scale DI
INavigationViewFactory factory = new NavigationViewFactory();
INavigationView navigationXml = factory.Create(NavigationViewTypes.Product);
return navigationXml.GetNavigationXDocument(supplierID, viewName, selectedProductNavigationView);
}
And the second one (which is never entered)
public XDocument AddOptionsToNavigationMenu(XDocument menu)
{
menu.Element(XmlNames.NodeNames.MenuItems).Add(
new XElement(XmlNames.NodeNames.MenuItem,
new XAttribute(XmlNames.AttributeNames.ID, "27301D05-EBBB-4F39-AC74-B0E944F26C52"),
new XAttribute(XmlNames.AttributeNames.DefaultName, "Options"),
new XAttribute(XmlNames.AttributeNames.NameTranslationID, "9999"),
new XAttribute(XmlNames.AttributeNames.DisplayMode, "Options"),
new XElement(XmlNames.NodeNames.MenuItem,
new XAttribute(XmlNames.AttributeNames.ID, "27301D05-EBBB-4F39-AC74-B0E944F26C57"),
new XAttribute(XmlNames.AttributeNames.NameTranslationID, "9999"),
new XAttribute(XmlNames.AttributeNames.DefaultName, "Notifications"),
new XElement(XmlNames.NodeNames.Subscriptions,
new XElement(XmlNames.NodeNames.Subscription,
new XAttribute(XmlNames.AttributeNames.ID, "7"),
new XAttribute(XmlNames.AttributeNames.DefaultName, "Subscriptions"))))));
return menu;
}
I put breakpoints before, on and after the method call as well as inside of the method. If I run the application, I can debug right through the method. But when I run some test cases, that cover this bit of code, they method call is never entered. Instead, the code equals navigationView to null. I fixed this by putting the method's code in the first class, but I'd like to know why this is an issue.
EDIT
Here is the code of one of the test cases that causes the faulty behavior when tested.
[TestMethod]
public void GetProductDetailNavigationModel_ProductWith3FieldValuesAnd2Documents_MappedObjectIsNotNull()
{
// Arrange
DDSInterfaceBlock.Current.IsImpersonated = false;
Domain.Supplier supplier = new Domain.Supplier().Init();
Domain.User user = new Domain.User().Init().Create();
Domain.Language language = new Domain.Language().Init();
Domain.Product product = new Domain.Product().Init().LinkSupplier(supplier);
Domain.ProductOverview.ProductDetail productDetail = ArrangeProductDetailData(supplier, user, language, product);
XDocument document = ArrangeXDocument(productDetail);
ProductDetail svc = new ProductDetail();
IProduct bus = MockRepository.GenerateStub<IProduct>();
bus.Stub(t => t.GetProductNavigationXDocument(supplier.Id, null, string.Empty))
.IgnoreArguments()
.Return(document);
bus.Stub(t => t.GetProductDetail(supplier.Id, user.Id, product.Id, language.Id, language.Id))
.IgnoreArguments()
.Return(productDetail);
svc.ProductBUS = bus;
svc.UserBUS = MockRepository.GenerateMock<BUS.Interfaces.IUser>();
svc.UserBUS
.Stub(t => t.CheckIfUserInPRAGroup(Guid.Empty))
.IgnoreArguments()
.Return(false);
// Act
Domain.ProductOverview.ProductDetailNavigationModel result
= svc.GetProductDetailNavigationModel(supplier.Id, user.Id, product.Id, language.Id, language.Id);
// Assert
Assert.IsNotNull(result);
}
Could it be because you have a stub for GetProductNavigationXDocument, but there is not sub for AddOptionsToNavigationMenu
I get a lof of syntax errors(missing simocolons...), when writing it like
IGlobal[] all;
public MainWindow()
{
InitializeComponent();
all = { new ATM(), new Bank()};
}
Even this does not work:
IGlobal[] all;
all= { new ATM(), new Bank()};
But as soon as I write it in one line(for example in a method) it works:
IGlobal[] all= { new ATM(), new Bank()};
"IGlobal" inherits only from "IDisposable". "ATM" and "Bank" inherit from "IGlobal" and 1 custom abstract class.
What is the problem here, what can I do ?
It is the syntax, where initializer and new is not exactly the same thing, and you cannot force it the way you want. All you can do is telling explicit array type
all = new IGlobal[] { new ATM(), new Bank() };
Or this will work too, but I suggest NOT to use it unless you want to deliberately make your co-workers confused.
all = new[] { (IGlobal) new ATM(), new Bank() };