public void InMemoryAccountRepository_AddAccountAsync_AccountAlreadyAdded()
            {
                var accounts = new List <Account>()
                {
                    new Account(),
                    new Account()
                };
                Account account             = new Account();
                var     expectedResult1     = true;
                var     expectedResult2     = false;
                var     expectedCount       = accounts.Count + 1;
                var     expectedLastAccount = account;

                var repository = new InMemoryAccountRepository(accounts);

                var actual1           = repository.AddAsync(account).GetAwaiter().GetResult();
                var actual2           = repository.AddAsync(account).GetAwaiter().GetResult();
                var actualCount       = accounts.Count;
                var actualLastAccount = accounts.Last();

                Assert.AreEqual(expectedResult1, actual1);
                Assert.AreEqual(expectedResult2, actual2);
                Assert.AreEqual(expectedCount, actualCount);
                Assert.AreSame(expectedLastAccount, actualLastAccount);
            }
            public void InMemoryAccountRepository_ContainsAsync_True()
            {
                var account  = new Account();
                var accounts = new List <Account>()
                {
                    new Account(),
                    account,
                    new Account()
                };
                var repository = new InMemoryAccountRepository(accounts);
                var expected   = true;

                var actual = repository.ContainsAsync(account).GetAwaiter().GetResult();

                Assert.AreEqual(expected, actual);
            }
            public void InMemoryAccountRepository_RemoveAccountAsync_AccountNotInList()
            {
                var account  = new Account();
                var accounts = new List <Account>()
                {
                    new Account(),
                    new Account()
                };
                var expectedResult = false;

                var repository = new InMemoryAccountRepository(accounts);

                var actual = repository.UpdateAsync(account).GetAwaiter().GetResult();

                Assert.AreEqual(expectedResult, actual);
            }
            public void InMemoryAccountRepository_GetAllAccountsAsync()
            {
                var accounts = new List <Account>()
                {
                    new Account(),
                    new Account(),
                    new Account()
                };
                var repository = new InMemoryAccountRepository(accounts);

                var actualAccounts = repository.GetAllAsync().GetAwaiter().GetResult();

                Assert.AreEqual(accounts.Count, actualAccounts.Length);
                for (int i = 0; i < accounts.Count; i++)
                {
                    Assert.AreSame(accounts[i], actualAccounts[i]);
                }
            }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(ExceptionFilter));
                options.Filters.Add(typeof(ModelValidationFilter));
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "My API", Version = "v1"
                });
            });

            IAccountRepository accountRepository = new InMemoryAccountRepository(new List <Account>());
            var accountManager = new AccountManager(accountRepository);

            var totpManager = new TotpManager(new TotpGenerator(),
                                              Configuration["TotpSettings:totpSecretKey"],
                                              Configuration.GetValue <int>("TotpSettings:totpTokenLifetimeInSeconds"),
                                              new InMemoryTotpTokenRepository(new Dictionary <string, int>()));

            var smsManager  = new SmsManager();
            var text        = File.ReadAllText("places.json");
            var places      = JsonConvert.DeserializeObject <List <Place> >(text);
            var tripManager = new TripManager(new AirTicketManager(new AirTicketsApi(
                                                                       Configuration["AirApiSettings:token"],
                                                                       Configuration["AirApiSettings:url"])),
                                              new InMemoryPlaceRepository(places),
                                              new InMemoryTripRepository(new List <Trip>()));

            services.AddSingleton(ConfigureSecurity(services));
            services.AddSingleton(tripManager);
            services.AddSingleton(accountManager);
            services.AddSingleton(totpManager);
            services.AddSingleton(smsManager);
        }
            public void InMemoryAccountRepository_AddAccountAsync_Valid()
            {
                var accounts = new List <Account>()
                {
                    new Account(),
                    new Account()
                };
                Account account             = new Account();
                var     expectedResult      = true;
                var     expectedCount       = accounts.Count + 1;
                var     expectedLastAccount = account;

                var repository = new InMemoryAccountRepository(accounts);

                var actual            = repository.AddAsync(account).GetAwaiter().GetResult();
                var actualCount       = accounts.Count;
                var actualLastAccount = accounts.Last();

                Assert.AreEqual(expectedResult, actual);
                Assert.AreEqual(expectedCount, actualCount);
                Assert.AreSame(expectedLastAccount, actualLastAccount);
            }
            public void InMemoryAccountRepository_RemoveAccountAsync_AccountNull()
            {
                var accounts = new List <Account>()
                {
                    new Account(),
                    new Account()
                };
                Account account             = null;
                var     expectedResult      = false;
                var     expectedCount       = accounts.Count;
                var     expectedLastAccount = accounts.Last();

                var repository = new InMemoryAccountRepository(accounts);

                var actual            = repository.RemoveAsync(account).GetAwaiter().GetResult();
                var actualCount       = accounts.Count;
                var actualLastAccount = accounts.Last();

                Assert.AreEqual(expectedResult, actual);
                Assert.AreEqual(expectedCount, actualCount);
                Assert.AreSame(expectedLastAccount, actualLastAccount);
            }