Click here to Skip to main content
15,887,485 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: how to open dll file Pin
Eddy Vluggen12-Jun-19 1:16
professionalEddy Vluggen12-Jun-19 1:16 
GeneralRe: how to open dll file Pin
Richard Deeming12-Jun-19 3:37
mveRichard Deeming12-Jun-19 3:37 
GeneralRe: how to open dll file Pin
Richard MacCutchan25-May-19 5:52
mveRichard MacCutchan25-May-19 5:52 
QuestionMessage Closed Pin
21-Apr-19 6:53
Member 1432178121-Apr-19 6:53 
AnswerRe: 阿萨德群无若群无若无群若 Pin
Richard Andrew x6421-Apr-19 7:32
professionalRichard Andrew x6421-Apr-19 7:32 
QuestionPassing Value from XAML to ViewModel Pin
Jassim Rahma20-Apr-19 13:45
Jassim Rahma20-Apr-19 13:45 
AnswerRe: Passing Value from XAML to ViewModel Pin
Gerry Schmitz21-Apr-19 5:56
mveGerry Schmitz21-Apr-19 5:56 
QuestionWriting unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper19-Apr-19 14:32
simpledeveloper19-Apr-19 14:32 
Hi friends,

I am writing a Unit Test for the method, which has two methods of the same Service are being called, Test method is for the exception case, in one method the Service should return null, it is doing properly, but in the next method it should throw ApplicationException, but it is not throwing, there is no other way to make exception thrown as I need pass the request object and it won't fail there and then calling the Service.
Below is the code for Unit Test, any help would be very very helpful
[TestMethod]
[ExpectedException(typeof(ApplicationException))]
public async Task RegisterOnlineAccountAsync_ExceptionTest()
{
    var mockRequest = new OnlineRegistration
    {
        AccountNumber = "5494526855",
        Last4DigitsOfSSN = "4321",
        EmailAddress = "abcd@ding.com"
    };

    var mockPgeAuthResponse = new PgeAuthenticatedUser
    {
        PersonId = "9013050000",
        Email = "abcd@ding.com"
    };

    PgeAuthenticatedUser mockPgeAuthResponseNull = null;

    var mockCCBResponse = new LocatePersonResponse
    {
        PersonIdList = new List<string> {"9013050000"},
        AccountInfoTypes = new List<AccountInfoType>
        {
            new AccountInfoType
            {
                AccountNumber = "5494526855",
                AccountType = "RES",
                MainPersonId = "9013050000"
            },
            new AccountInfoType
            {
                AccountNumber = "5494526856",
                AccountType = "RES",
                MainPersonId = "9013050000"
            }
        }
    };

    var mockPaperlessBillResponse = new PaperlessBillResponse
    {
        EmailAddress = "abcd@ding.com",
        IsPaperless = false,
        ReceivesCopyOfBill = false
    };

    var mockPersonDetailResponse = new PersonDetailResponse
    {
        PersonId = "9013050000",
        PersonalIdentifications = new List<PersonalIdentification>
        {
            new PersonalIdentification
            {
                Type = "SSN",
                Value = "4321"
            }
        }
    };

    this._locatePersonContactProxy =
        Mock.Of<ILocatePersonContactProxy>(e => e.LocatePersonDetailsAsync(It.IsAny<LocatePersonRequest>()) == Task.FromResult(mockCCBResponse));

    this._personDetailsProxy = Mock.Of<IPersonDetailsProxy>(e => e.PersonDetailsGetAsync(It.IsAny<string>()) == Task.FromResult(mockPersonDetailResponse));

    this._personManager = Mock.Of<IPersonManager>(e => e.UpdateCcbCssWebUserDetailsAsync(It.IsAny<List<string>>(), It.IsAny<string>()
                                                           , It.IsAny<string>(), It.IsAny<string>()) == Task.FromResult(mockPgeAuthResponse));

    this._paperlessBillProxy = Mock.Of<IPaperlessBillProxy>(e => e.PaperlessBillingGetAsync(It.IsAny<string>(), It.IsAny<string>()) == Task.FromResult(mockPaperlessBillResponse));

    this._paperlessManager = Mock.Of<IPaperlessManager>(e =>
        e.PaperlessBillingPreferencesUpdateAsync(It.IsAny<PaperlessBilling>(), It.IsAny<string>(), It.IsAny<string>()) == Task.FromResult(false));

    this._customerContactProxy = Mock.Of<ICustomerContactProxy>(e => e.CreateLogAsync(It.IsAny<CustomerContactRequest>()) == Task.FromResult(""));

    this._pgeAuthAdminProxy =  Mock.Of<IPgeAuthAdminProxy>();

    //this._pgeAuthAdminProxy =
    //    Mock.Of<IPgeAuthAdminProxy>(e => e.GetUserByNameAsync(It.IsAny<string>()) == Task.FromResult(mockPgeAuthResponseNull));

    var pgeAuth = new Mock<IPgeAuthAdminProxy>();

    pgeAuth.Setup(p => p.GetUserByNameAsync(It.IsAny<string>())).ReturnsAsync(mockPgeAuthResponseNull);

    var pgeAuth1 = new Mock<IPgeAuthAdminProxy>();
    pgeAuth1.Setup(p => p.CreateUserAccountAsync(It.IsAny<CreateUserAccountRequest>())).Throws(new Exception());

    this._pgeMessagingProxy = Mock.Of<IPgeMessagingProxy>(e => e.SendPgeMessageAsync(It.IsAny<PgeMessageRequest>()) == Task.FromResult(false));

    this._registrationManager = GetManager();

    await this._registrationManager.RegisterOnlineAccountAsync(mockRequest).ConfigureAwait(false);

    Assert.ThrowsException<Exception>
    (() => new ApplicationException(
        $"EmailAddress: ({mockRequest.EmailAddress}) - PersonId: ({mockRequest.PersonId}) - AccountNumber: ({mockRequest.AccountNumber}): Exception caught in AccountManager.Registration.CreateUserOnlineAccountAsync."));
}

The following is the method that needs to be tested:
public async Task<RegisterOnlineAccountResult> RegisterOnlineAccountAsync(OnlineRegistration registration)
{
    var registerOnlineAccountResult = new RegisterOnlineAccountResult();

    if (registration.PersonId.IsNullOrEmpty())
    {
        var personDetailsResponse = await this._personDetailsProxy.PersonDetailsGetAsync(registration.PersonId).ConfigureAwait(false);

        var cssWebUser = personDetailsResponse?.PersonContactDetails?.FirstOrDefault(pc => pc.ContactType == CSSWebUser);

        var xxxAuthenticatedUser = await this._xxxAuthAdminProxy.GetUserByNameAsync(registration.EmailAddress).ConfigureAwait(false);

        if (cssWebUser != null)
        {
            await EnrollUserAsync(response, registration).ConfigureAwait(false);

            return new RegisterOnlineAccountResult { OnlineRegistrationAccountResultStatus = OnlineRegistrationAccountResultStatus.Success };
        }

        if (xxxAuthenticatedUser != null) return new RegisterOnlineAccountResult { OnlineRegistrationAccountResultStatus = OnlineRegistrationAccountResultStatus.WebRegisteredEmailFound };

        await EnrollUserAsync(response, registration).ConfigureAwait(false);

        registerOnlineAccountResult.OnlineRegistrationAccountResultStatus = OnlineRegistrationAccountResultStatus.Success;
    }
    else
    {
        await EnrollStartServiceUser(registration).ConfigureAwait(false);
        registerOnlineAccountResult.OnlineRegistrationAccountResultStatus = OnlineRegistrationAccountResultStatus.Success;
    }

    return registerOnlineAccountResult;
}


private async Task EnrollUserAsync(LocatePersonResponse response, OnlineRegistration onlineRegistration)
{
    await CreateUserOnlineAccountAsync(onlineRegistration).ConfigureAwait(false);
}


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.xxxResidentialAcct) : nameof(OnlineAccountType.xxxCommercialAcct),
            PersonId = registration.PersonId,
            Password = registration.Password,
            UserName = registration.EmailAddress,
            CcbAccountId = registration.AccountNumber,
            BusinessPersonId = !registration.IsResidential ? registration.MainPersonId : null
        };

        return await this._xxxAuthAdminProxy.CreateUserAccountAsync(request).ConfigureAwait(false);
    }
    catch (Exception ex)
    {
        throw new ApplicationException(
            $"EmailAddress: ({registration.EmailAddress}) - PersonId: ({registration.PersonId}) - AccountNumber: ({registration.AccountNumber}): Exception caught in AccountManager.Registration.CreateUserOnlineAccountAsync.",
            ex);
    }
}

If you have seen it here, the _xxxAuthAdminProxy is being called with two different methods 1. GetUserByNameAsync and 2. CreateUserAccountAsync, when condition that needs to happen is GetUserByNameAsync method should return a null where as CreateUserAccountAsync method should throw an exception. any help would be greatly helpful - thanks in advance.
AnswerRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz21-Apr-19 6:08
mveGerry Schmitz21-Apr-19 6:08 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper21-Apr-19 16:58
simpledeveloper21-Apr-19 16:58 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz22-Apr-19 4:36
mveGerry Schmitz22-Apr-19 4:36 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper22-Apr-19 7:07
simpledeveloper22-Apr-19 7:07 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz22-Apr-19 8:28
mveGerry Schmitz22-Apr-19 8:28 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper22-Apr-19 8:55
simpledeveloper22-Apr-19 8:55 
Question“Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
VictorSotnikov9-Apr-19 5:52
VictorSotnikov9-Apr-19 5:52 
AnswerRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
Gerry Schmitz9-Apr-19 6:15
mveGerry Schmitz9-Apr-19 6:15 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
VictorSotnikov9-Apr-19 6:28
VictorSotnikov9-Apr-19 6:28 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
Gerry Schmitz10-Apr-19 5:39
mveGerry Schmitz10-Apr-19 5:39 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
David A. Gray3-May-19 7:33
David A. Gray3-May-19 7:33 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
Gerry Schmitz3-May-19 8:48
mveGerry Schmitz3-May-19 8:48 
Questionregarding the cryptarithmatic code in your website Pin
Member 141248901-Apr-19 4:32
Member 141248901-Apr-19 4:32 
AnswerRe: regarding the cryptarithmatic code in your website Pin
Richard MacCutchan1-Apr-19 4:42
mveRichard MacCutchan1-Apr-19 4:42 
QuestionIs there any way to initialize or set values for this declaration as inline statement private IList<MockData<OnlineRegistration, OnlineRegistration, OnlineRegistration>> _registerMocks; Pin
simpledeveloper28-Mar-19 7:18
simpledeveloper28-Mar-19 7:18 
AnswerRe: Is there any way to initialize or set values for this declaration as inline statement private IList<MockData<OnlineRegistration, OnlineRegistration, OnlineRegistration>> _registerMocks; Pin
Eddy Vluggen29-Mar-19 2:33
professionalEddy Vluggen29-Mar-19 2:33 
QuestionASP.Net 4.5 to ASP.Net core 2.0.1 migration issue of Authentication Pin
geetha naidu24-Mar-19 11:38
geetha naidu24-Mar-19 11:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.