<commit_before>﻿// Copyright (c) <NAME>, 2017. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

namespace MartinCostello.LondonTravel.Site.Identity
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using MartinCostello.LondonTravel.Site.Services;
    using Microsoft.AspNetCore.Identity;

    /// <summary>
    /// A class representing a custom implementation of a user store. This class cannot be inherited.
    /// </summary>
    public sealed class UserStore : IUserStore<LondonTravelUser>, IUserLoginStore<LondonTravelUser>, IUserEmailStore<LondonTravelUser>
    {
        /// <summary>
        /// The <see cref="IDocumentClient"/> to use. This field is read-only.
        /// </summary>
        private readonly IDocumentClient _client;

        /// <summary>
        /// Whether the instance has been disposed.
        /// </summary>
        private bool _disposed;

        /// <summary>
        /// Initializes a new instance of the <see cref="UserStore"/> class.
        /// </summary>
        /// <param name="client">The <see cref="IDocumentClient"/> to use.</param>
        /// <exception cref="">
        /// <paramref name="client"/> is <see langword="null"/>.
        /// </exception>
        public UserStore(IDocumentClient client)
        {
            _client = client ?? throw new ArgumentNullException(nameof(client));
        }

        /// <inheritdoc />
        public async Task AddLoginAsync(LondonTravelUser user, UserLoginInfo login, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (login == null)
            {
                throw new ArgumentNullException(nameof(login));
            }

            if (!user.Logins.Any((p) => p.LoginProvider == login.LoginProvider))
            {
                user.Logins.Add(LondonTravelLoginInfo.FromUserLoginInfo(login));
            }<commit_msg>Throw instead of doing a no-op update<commit_after>﻿// Copyright (c) <NAME>, 2017. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

namespace MartinCostello.LondonTravel.Site.Identity
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using MartinCostello.LondonTravel.Site.Services;
    using Microsoft.AspNetCore.Identity;

    /// <summary>
    /// A class representing a custom implementation of a user store. This class cannot be inherited.
    /// </summary>
    public sealed class UserStore : IUserStore<LondonTravelUser>, IUserLoginStore<LondonTravelUser>, IUserEmailStore<LondonTravelUser>
    {
        /// <summary>
        /// The <see cref="IDocumentClient"/> to use. This field is read-only.
        /// </summary>
        private readonly IDocumentClient _client;

        /// <summary>
        /// Whether the instance has been disposed.
        /// </summary>
        private bool _disposed;

        /// <summary>
        /// Initializes a new instance of the <see cref="UserStore"/> class.
        /// </summary>
        /// <param name="client">The <see cref="IDocumentClient"/> to use.</param>
        /// <exception cref="">
        /// <paramref name="client"/> is <see langword="null"/>.
        /// </exception>
        public UserStore(IDocumentClient client)
        {
            _client = client ?? throw new ArgumentNullException(nameof(client));
        }

        /// <inheritdoc />
        public async Task AddLoginAsync(LondonTravelUser user, UserLoginInfo login, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (login == null)
            {
                throw new ArgumentNullException(nameof(login));
            }

            if (user.Logins.Any((p) => p.LoginProvider == login.LoginProvider))
            {
                throw new InvalidOperationException($"Failed to add login for provider '{login.LoginProvider}' for user '{user.Id}' as a login for that provider already exists.");
            }

            user.Logins.Add(LondonTravelLoginInfo.FromUserLoginInfo(login));
{'fraction_non_alphanumeric': 0.11289612676056338, 'fraction_numerical': 0.002640845070422535, 'mean_word_length': 2.1694560669456067, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2262945', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1122, 'n_words': 334}