public async Task TokenSystemDbService_AddCustomerDetails_ReturnsCreatedSuccess()
        {
            // Arrange
            var      mockContainer    = new Mock <Container>();
            var      mockCosmosClient = new Mock <CosmosClient>();
            var      responseMock     = new Mock <ItemResponse <Customer> >();
            Customer newCustomer      = new Customer
            {
                FirstName     = "New",
                Surname       = "Customer",
                Age           = 35,
                CustomerType  = CustomerType.AccountHolder,
                AccountNumber = 34567,
                Token         = new Token {
                    ServiceType = ServiceType.Transaction
                }
            };

            var existingCusotmers = new List <Customer>
            {
                new Customer
                {
                    Id            = "1111-11111-11",
                    FirstName     = "FirstCustoer",
                    Surname       = "SecondName",
                    Age           = 35,
                    CustomerType  = CustomerType.AccountHolder,
                    AccountNumber = 123456,
                    Token         = new Token {
                        ServiceType = ServiceType.Transaction, TokenNumber = 1
                    }
                }
            }.AsQueryable();

            mockContainer.Setup(x => x.GetItemLinqQueryable <Customer>(true, null, null))
            .Returns((IOrderedQueryable <Customer>)existingCusotmers);

            mockCosmosClient.Setup(x => x.GetContainer(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockContainer.Object);

            // Act
            var serviceUnderTest = new TokenSystemDbService(mockCosmosClient.Object, It.IsAny <string>(), It.IsAny <string>());

            var response = await serviceUnderTest.AddCustomerDetails(newCustomer);


            // Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(2, response.TokenNumber);
            Assert.AreEqual(0, response.Counter);
            Assert.AreEqual(Status.InQueue, response.Status);
        }
        public void TokenSystemDbService_GetCustomerById_ReturnsSingleCustomerSuccess()
        {
            // Arrange
            var mockContainer    = new Mock <Container>();
            var mockCosmosClient = new Mock <CosmosClient>();
            var responseMock     = new Mock <ItemResponse <Customer> >();

            var existingCusotmers = new List <Customer>
            {
                new Customer
                {
                    Id            = "1111-11-111",
                    FirstName     = "First",
                    Surname       = "SecondName",
                    Age           = 35,
                    CustomerType  = CustomerType.AccountHolder,
                    AccountNumber = 123456,
                    Token         = new Token {
                        ServiceType = ServiceType.Transaction, TokenNumber = 1, Counter = 0, Status = Status.InQueue
                    }
                },
                new Customer {
                    Id           = "2222-222-222",
                    FirstName    = "Second",
                    Surname      = "Customer",
                    Age          = 35,
                    CustomerType = CustomerType.Guest,
                    SocialNumber = 76543,
                    Token        = new Token {
                        ServiceType = ServiceType.Service, TokenNumber = 2, Counter = 0, Status = Status.InQueue
                    }
                }
            }.AsQueryable();

            mockContainer.Setup(x => x.GetItemLinqQueryable <Customer>(true, null, null))
            .Returns((IOrderedQueryable <Customer>)existingCusotmers);

            mockCosmosClient.Setup(x => x.GetContainer(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockContainer.Object);

            var serviceUnderTest = new TokenSystemDbService(mockCosmosClient.Object, It.IsAny <string>(), It.IsAny <string>());

            // Act
            var response = serviceUnderTest.GetCustomerById(existingCusotmers.Last().Id);

            // Assert
            Assert.AreEqual(existingCusotmers.Last(), response);
        }
        /// Creates a Cosmos DB database and a container with the specified partition key.
        private static async Task <TokenSystemDbService> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ContainerName").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            TokenSystemDbService cosmosDbService       = new TokenSystemDbService(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/token/serviceType");

            return(cosmosDbService);
        }
        public void UpdateTokenStatusAsync_TokenSystemDbService_UpdateTokenStatusFails()
        {
            // Arrange
            var mockContainer    = new Mock <Container>();
            var mockCosmosClient = new Mock <CosmosClient>();
            var responseMock     = new Mock <ItemResponse <Customer> >();

            var existingCusotmers = new List <Customer>
            {
                new Customer
                {
                    Id            = "1111-11-111",
                    FirstName     = "First",
                    Surname       = "SecondName",
                    Age           = 35,
                    CustomerType  = CustomerType.AccountHolder,
                    AccountNumber = 123456,
                    Token         = new Token {
                        ServiceType = ServiceType.Transaction, TokenNumber = 1, Counter = 0, Status = Status.InQueue
                    }
                }
            }.AsQueryable();

            mockContainer.Setup(x => x.GetItemLinqQueryable <Customer>(true, null, null))
            .Returns((IOrderedQueryable <Customer>)existingCusotmers);

            mockCosmosClient.Setup(x => x.GetContainer(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockContainer.Object);

            var serviceUnderTest = new TokenSystemDbService(mockCosmosClient.Object, It.IsAny <string>(), It.IsAny <string>());

            // Act
            var response = serviceUnderTest.UpdateTokenStatusAsync("abcd-124", Status.Served);

            // Assert
            Assert.IsFalse(response.Result);
        }
        public void TokenSystemDbService_GetTokenDetailsForBank_ReturnsBankDashboardDetails()
        {
            // Arrange
            var mockContainer    = new Mock <Container>();
            var mockCosmosClient = new Mock <CosmosClient>();
            var responseMock     = new Mock <ItemResponse <Customer> >();

            var existingCusotmers = new List <Customer>
            {
                new Customer
                {
                    Id            = "1111-11-111",
                    FirstName     = "First",
                    Surname       = "SecondName",
                    Age           = 35,
                    CustomerType  = CustomerType.AccountHolder,
                    AccountNumber = 123456,
                    Token         = new Token {
                        ServiceType = ServiceType.Transaction, TokenNumber = 1, Counter = 0, Status = Status.InQueue
                    }
                },
                new Customer {
                    Id           = "2222-222-222",
                    FirstName    = "Second",
                    Surname      = "Customer",
                    Age          = 35,
                    CustomerType = CustomerType.Guest,
                    SocialNumber = 76543,
                    Token        = new Token {
                        ServiceType = ServiceType.Service, TokenNumber = 2, Counter = 2, Status = Status.InCounter
                    }
                }
            }.AsQueryable();

            var expected = new List <Token>
            {
                new Token
                {
                    TokenNumber = 1,
                    Status      = Status.InQueue,
                    Counter     = 0,
                    ServiceType = ServiceType.Transaction
                },
                new Token
                {
                    TokenNumber = 2,
                    Status      = Status.InCounter,
                    Counter     = 2,
                    ServiceType = ServiceType.Service
                }
            };

            mockContainer.Setup(x => x.GetItemLinqQueryable <Customer>(true, null, null))
            .Returns((IOrderedQueryable <Customer>)existingCusotmers);

            mockCosmosClient.Setup(x => x.GetContainer(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockContainer.Object);

            var serviceUnderTest = new TokenSystemDbService(mockCosmosClient.Object, It.IsAny <string>(), It.IsAny <string>());

            // Act
            var response = serviceUnderTest.GetTokenDetailsForBank();

            // Assert
            Assert.AreEqual(expected.Count(), response.Count());
            Assert.AreEqual(expected[0].Counter, response.ToList()[0].Counter);
            Assert.AreEqual(expected[0].Status, response.ToList()[0].Status);
            Assert.AreEqual(expected[0].TokenNumber, response.ToList()[0].TokenNumber);
            Assert.AreEqual(expected[0].ServiceType, response.ToList()[0].ServiceType);
            Assert.AreEqual(expected[1].Counter, response.ToList()[1].Counter);
            Assert.AreEqual(expected[1].Status, response.ToList()[1].Status);
            Assert.AreEqual(expected[1].TokenNumber, response.ToList()[1].TokenNumber);
            Assert.AreEqual(expected[1].ServiceType, response.ToList()[1].ServiceType);
        }