|
I think you need to pick an exception that's a little lower in the food chain; you're targetting what would be intended for an app level handler.
Quote: You should derive custom exceptions from the Exception class rather than the ApplicationException class. You should not throw an ApplicationException exception in your code, and you should not catch an ApplicationException exception unless you intend to re-throw the original exception.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I am able to generate mock for one Condition, but not for another condition like, the method GetUserByNameAsync is returning null for the Proxy that I set up as
this._xxxAuthAdminProxy = Mock.Of<IxxxAuthAdminProxy>();
var xxxAuth = new Mock<IxxxAuthAdminProxy>();
xxxAuth.Setup(p => p.GetUserByNameAsync(It.IsAny<string>()))
.ReturnsAsync(mockxxxAuthResponseNull);
xxxAuth.Setup(p => p.CreateUserAccountAsync(It.IsAny<CreateUserAccountRequest>()))
.ThrowsAsync(new Exception());
But CreateUserAccountAsync is not returning exception, any help my friend, anything would be greatly helpful. Thank you.
|
|
|
|
|
I think I told you not to use "ApplicationException" for exceptions "you generate / throw" in you app ... use something else; e.g. throw new Exception("My test blew up as expected");
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Where in the Unit Test or in the actual method? From the Actual method I have to use the ApplicationException, even though, I just want to at least throw some Exception from my Unit Test call, but no Exception is being thrown, there is very less help from Online, it seems complicated any help would be very helpful brother rather than giving me high level help.
And I am getting the following error in the Unit Test:
Assert.ThrowsException failed. No exception thrown. Exception exception was expected.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at CustomerServiceWeb.Library.Test.Registration.RegistrationManagerTest.<RegisterOnlineAccountAsync_ExceptionTest>d__18.MoveNext() in C:\SourceCode\FlexPricing\CustomerServiceWeb.Library.Test\Registration\RegistrationManagerTest.cs:line 692
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Basically Unit test is failing because the Method is not throwing Exception, let it be any Exception, I want to just throw an Exception
I did change it as you said removed the ApplicationException, but still the Unit test is failing:
private async Task<bool> CreateUserOnlineAccountAsync(OnlineRegistration registration)
{
try
{
var request = new CreateUserAccountRequest
{
Description = $"Account created: {DateTime.Now:MM/dd/yyyy}",
AccountType = registration.IsResidential ? nameof(OnlineAccountType.PGEResidentialAcct) : nameof(OnlineAccountType.PGECommercialAcct),
PersonId = registration.PersonId,
Password = registration.Password,
UserName = registration.EmailAddress,
CcbAccountId = registration.AccountNumber,
BusinessPersonId = !registration.IsResidential ? registration.MainPersonId : null
};
return await this._pgeAuthAdminProxy.CreateUserAccountAsync(request).ConfigureAwait(false);
}
catch (Exception ex)
{
throw new Exception("My test blew up as expected");
}
}
modified 22-Apr-19 13:40pm.
|
|
|
|
|
[TestMethod]
[ExpectedException(typeof(ApplicationException))]
public async Task RegisterOnlineAccountAsync_ExceptionTest()
{
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes I removed that as well, still not throwing any Exception, any idea my friend?
I did change it to this, still the Exception was not being generated:
[TestMethod]
public async Task RegisterOnlineAccountAsync_ExceptionTest()
Any help would be very very helpful my friend, it seems the problem is in the SetUp itself, I feel so, but I don't know how to generate Exception when the same Proxy was used before for a different method call.
modified 23-Apr-19 17:02pm.
|
|
|
|
|
I have an .NET 4.0 assembly; it is registered in GAC and works as part of a BizTalk “orchestration”.
Sometimes I get the following error - “Collection was modified; enumeration operation might not execute. : System.InvalidOperationException: Collection was modified; enumeration operation might not execute.”. I cannot reproduce it; when I run the same processing of the same data, my assembly does not generate the error in this place.
The error happens when I call ‘.Where(<condition>).ToArray()’ for a datatable object: an object of classd System.Data.TypedTableBase<mydatarowclass>.
Here is the code:
..................
int? setTypeGroupId;
...
return instances.WorkContributors.Where
(
c =>
!c.IsInterestedPartyNoNull()
&& c.InterestedPartyNo == publisherIpNo
&& c.SetTypeNo == 1
&& (c.RecordType == "SPU")
&& c.TypeCode == "E"
&& (!setTypeGroupId.HasValue ||
(setTypeGroupId.HasValue && c.SetTypeGroupID == setTypeGroupId))
)
.ToArray();
..................
The object ‘instances’ is a dataset – my class produced from System.Data.DataSet.
The property ‘instances.WorkContributors’ is a datatable: an object of class System.Data.TypedTableBase<mydatarowclass>.
The class MyDataRowClass is produced from System.Data.DataRow.
The call stack after the error was the following:
Collection was modified; enumeration operation might not execute. : System.InvalidOperationException: Collection was modified; enumeration operation might not execute.
at System.Data.RBTree`1.RBTreeEnumerator.MoveNext()
at System.Linq.Enumerable.<castiterator>d__97`1.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MyProduct.FileParser.Types.CWR.PWRType.GetPublishers(CWRWorkInstances instances, Nullable`1 setTypeGroupId)
at MyProduct.FileParser.Validation.Concreate.PwrTypeValidation.ValidatePublisherNumber()
at MyProduct.FileParser.Validation.Concreate.PwrTypeValidation.Validate()
at MyProduct.FileParser.Types.CWR.PWRType.StoreRecord(CWRWorkInstances workInstances, CWRWorkParsingContext context)
at MyProduct.FileParser.Groups.CWR.NWRGroup.StoreGroup(Int32 workBatchID, CWRFileCommonData commonData)
at MyProduct.FileParser.CWRParser.ProcessCWRFile(String fileName, Boolean wait, Boolean deleteFile, String sourceFileName)
I cannot understand why the error happens; and why it happens only sometimes and does not happen on the same processed data again.
The error “Collection was modified; enumeration operation might not execute.” Itself is pretty straightforward for me; but I do not see why it happens in that my code. The error is excepted if a code like this:
foreach (DataRow currRow in _someDataTable.Rows)
{
if ()
{
someDataTable.Rows.Remove(currRow);
}
} But my code above just wants to enumerate System.Data.TypedTableBase<mydatarowclass> and convert the result into an array.
Any ideas?
|
|
|
|
|
|
Thank you for the answer, but still not clear:
1. Is this supposed to fix the problem; or to make the problem “stably reproducible”?
2. In any case – what is the root cause of the problem?
|
|
|
|
|
Did you try it? If not why not?
It has to do with "deferred execution". Probably "realizing" while you're "iterating" to an array.
But then again, maybe not. But since you didn't bother to try, we will never know.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
As I recall, a DataTable is not a snapshot, which means that its contents can be changed by another process, such as an insert query. Anything that changes the contents of the list in any way invalidates the snapshot upon which the enumeration depends.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
Tell him. I had no impact. I'll stick with the unmaterialized query result intrusion.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Respected sir,
I've gone through the cryptarithmetic code given in your website. In the description it was given that the starting letter should not be zero(resultantant string one greater than the operand),but in code execution we are getting the initial value as zero. Please explain.
|
|
|
|
|
Sorry but we have no idea what you are referring to. If this is a CodeProject article then please post your question in the form below the article. If it is referring to something else then please provide the link.
|
|
|
|
|
Hi I have a declaration that's as follows, I am looking to initialize this in single statement rather than initializing individually
private IList<MockData<OnlineRegistration, OnlineRegistration, OnlineRegistration>> _registerMocks;
What I want is obj1, obj2, obj3 of the OnlineRegistration Objects to be initialized within one single statement, it can have multiple lines, don't confuse but values of the these objects all should be set within one statement.
Like:
var obj1 = new OnlineRegistration {Id=1, Name="xyz"}
var obj2 = new OnlineRegistration {Id=2, Name="abc"}
var obj3 = new OnlineRegistration {Id=2, Name=".Net Fun"}
these objects should go into one single initialization of the above statement, any ways? please
|
|
|
|
|
simpledeveloper wrote: of the these objects all should be set within one statement. You are wasting time and effort to get them on a single line, while it has no benefit to do so.
Even more, if you make it into a single statement, it will execute and fail as one. If you use multiple statements, you can use breakpoints on each statement, and have them evaluate individually, which makes finding errors a bit simpeler.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello Developers, I am new to ASP.Net core 2.0.1, i studied the architecture of Authentication and identification in core framework,i facing some problems during migration, please help. In the Startup.cs file, I am using this piecce of code in ConfigureServices method
app.use(async (context, next) =>
{
await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await context.Authentication.ChallengeAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await next.Invoke();
}
Now in core, i dont know how to handle these 2 functions for logout
I get NULLREFERENCE Exception
var projectId = context?.Session?.GetInt("Project_Id"); when page is refershed after a while.
Please help me to resolve these issue.
Geetha
modified 25-Mar-19 4:36am.
|
|
|
|
|
Message Closed
modified 9-Mar-19 4:10am.
|
|
|
|
|
Just use MS Power BI for the desktop and be done with it.
Power BI Desktop | Microsoft Power BI
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
I sort of got that from his last line. Just wanted to irritate him by stealing his soapbox.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I am building an application in WPF for the first time. The application is intended to track employees who are hired by the company, track the hire type (e.g…assignment category…full time, part time, seasonal, intern). In addition, it will track which department to which an employee is assigned during their tenure with the company. Some employees are exposed to several different departments while employed in order to more fully round out their training or due to work loads.
The backend for this application is built in SQL Server and contains three tables. They are company employees, company departments, and assignment categories. Each obviously has its own primary key.
I have created a datagrid that, via Linq to SQL Classes, displays data from the company employees table. Each of the columns in the datagrid is a DataGridTextColumn except for one which is a DataGridComboBoxColumn. The DataGridTextColumn’s work fine. However, I cannot seem to get the binding correct. The column appears in the datagrid and is a working combobox. The issue is that I cannot find how to populate the combox with values from which the end user will select. This combobox will allow the end user to choose which under which assignment category an employee has been hired.
As an end result, this application will be used by the company owner to keep track of the number of employees that he has on hand and show who will be leaving each month due to being a seasonal worker or an intern.
Below is the code behind and the xaml. Please note that I have spent several days now researching this topic and cannot find anything that I can make work. I am confident that this is because I am just learning xaml and c#.
Can someone help me understand what I am doing wrong, please?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace staff_scheduling_tool.views
{
public partial class employees_new_employee : UserControl
{
assignment_typeDataContext dc = new assignment_typeDataContext(Properties.Settings.Default.db_employee_scheduling_applicationConnectionString);
public employees_new_employee()
{
InitializeComponent();
if (dc.DatabaseExists()) datagrid_search_results.ItemsSource = dc.companyemployees;
}
private void Save_changes_Click(object sender, RoutedEventArgs e)
{
dc.SubmitChanges();
}
}
}
<DataGrid Name="datagrid_search_results" Margin="10,25" Width="1400" Height="350" AlternatingRowBackground="LightGreen" GridLinesVisibility="None" SelectionUnit="Cell" BorderBrush="Transparent" BorderThickness="0" Background="Transparent" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding employee_id}" Width="Auto" Header=" Employee ID" />
<DataGridTextColumn Binding="{Binding last_name}" Width="Auto" Header=" Last Name" SortDirection="Ascending" />
<DataGridTextColumn Binding="{Binding first_name}" Width="Auto" Header=" First Name"/>
<DataGridTextColumn Binding="{Binding middle_name}" Width="Auto" Header=" Middle Name"/>
<DataGridTextColumn Binding="{Binding company_email}" Width="Auto" Header=" Company Email"/>
<DataGridComboBoxColumn Width="Auto" Header="Assignment Category" />
<DataGridTextColumn Binding="{Binding department_assignment_begin_date, StringFormat=d}" Width="Auto" Header=" Begin Date"/>
<DataGridTextColumn Binding="{Binding department_assignment_end_date, StringFormat=d}" Width="Auto" Header=" End Date"/>
</DataGrid.Columns>
</DataGrid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
<Button Name="save_changes" Content="Save Updates" Click="Save_changes_Click" Grid.Row="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="250" FontFamily="Sitka Banner" FontSize="24" FontStyle="Italic" FontWeight="ExtraBold"/>
</Grid>
modified 28-Feb-19 17:42pm.
|
|
|
|
|
|
So I was able to get the code below, but the combo box still will not populate. Can someone help me understand what I am still doing wrong, please?
<DataGrid ItemsSource="{Binding db_employee_scheduling_application}"
Name="datagrid_search_results" Margin="10,25" Width="1400"
Height="350" AlternatingRowBackground="LightGreen" GridLinesVisibility="None"
SelectionUnit="Cell" BorderBrush="Transparent" BorderThickness="0"
Background="Transparent" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding employee_id}" Width="Auto" Header=" Employee ID" />
<DataGridTextColumn Binding="{Binding last_name}" Width="Auto" Header=" Last Name" SortDirection="Ascending" />
<DataGridTextColumn Binding="{Binding first_name}" Width="Auto" Header=" First Name"/>
<DataGridTextColumn Binding="{Binding middle_name}" Width="Auto" Header=" Middle Name"/>
<DataGridTextColumn Binding="{Binding company_email}" Width="Auto" Header=" Company Email" />
<DataGridComboBoxColumn Width="Auto" Header="Assignment Category"
ItemsSource="{Binding assignment categories}"
DisplayMemberPath="assignment category name"
SelectedValuePath="assignment category id"
SelectedValueBinding="{Binding assignment category name}"/>
<DataGridTextColumn Binding="{Binding department_assignment_begin_date, StringFormat=d}" Width="Auto" Header=" Begin Date"/>
<DataGridTextColumn Binding="{Binding department_assignment_end_date, StringFormat=d}" Width="Auto" Header=" End Date"/>
</DataGrid.Columns>
</DataGrid>
|
|
|
|
|
Hey Gerry,
I appreciate your responses. However when I tried implementing your advice and the resulting combo box wouldn't even open. That is not to say that you gave bad advice, but to say that I am in need of more detailed instructions, please.
|
|
|
|