public async void UseClientCultureIfLanguageHeadersIsPresent()
            {
                // Arrange
                var aggregateStatsService = new Mock <IAggregateStatsService>(MockBehavior.Strict);
                var stats = new AggregateStats
                {
                    Downloads      = 2013,
                    TotalPackages  = 1000,
                    UniquePackages = 500
                };

                aggregateStatsService.Setup(s => s.GetAggregateStats()).Returns(Task.FromResult(stats));

                var request = new Mock <HttpRequestBase>();

                request.Setup(r => r.UserLanguages).Returns(new string[] { "vi-VN" });

                var controller = CreateController(aggregateStatsService, request);

                // Act

                var result = await InvokeAction(() => (controller.Totals()), controller) as JsonResult;

                // Asssert
                Assert.NotNull(result);
                dynamic data = result.Data;

                Assert.Equal("2.013", (string)data.Downloads);
                Assert.Equal("500", (string)data.UniquePackages);
                Assert.Equal("1.000", (string)data.TotalPackages);
            }
            public async Task IgnoresUserCultureAndReturnsStatisticsAsNumbers()
            {
                // Arrange
                var aggregateStatsService = new Mock <IAggregateStatsService>(MockBehavior.Strict);
                var stats = new AggregateStats
                {
                    Downloads      = 2013,
                    TotalPackages  = 1000,
                    UniquePackages = 500
                };

                aggregateStatsService.Setup(s => s.GetAggregateStats()).Returns(Task.FromResult(stats));

                var request = new Mock <HttpRequestBase>();

                request.Setup(r => r.UserLanguages).Returns(new string[] { "vi-VN" });

                var controller = CreateController(aggregateStatsService, request);

                // Act

                var result = await InvokeAction(() => (controller.Totals()), controller) as JsonResult;

                // Assert
                Assert.NotNull(result);
                dynamic data = result.Data;

                Assert.Equal(2013, data.Downloads);
                Assert.Equal(500, data.UniquePackages);
                Assert.Equal(1000, data.TotalPackages);
            }
            public async void UseServerCultureIfLanguageHeadersIsMissing()
            {
                // Arrange
                var currentCulture = CultureInfo.CurrentCulture;

                try
                {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");

                    var aggregateStatsService = new Mock <IAggregateStatsService>(MockBehavior.Strict);
                    var stats = new AggregateStats
                    {
                        Downloads      = 2013,
                        TotalPackages  = 1000,
                        UniquePackages = 500
                    };
                    aggregateStatsService.Setup(s => s.GetAggregateStats()).Returns(Task.FromResult(stats));

                    var controller = CreateController(aggregateStatsService);

                    // Act
                    var result = await controller.Totals() as JsonResult;

                    // Asssert
                    Assert.NotNull(result);
                    dynamic data = result.Data;

                    Assert.Equal("2,013", (string)data.Downloads);
                    Assert.Equal("500", (string)data.UniquePackages);
                    Assert.Equal("1,000", (string)data.TotalPackages);
                }
                finally
                {
                    Thread.CurrentThread.CurrentCulture = currentCulture;
                }
            }
            public async Task IgnoresServerCultureAndReturnsStatisticsAsNumbers()
            {
                // Arrange
                var currentCulture = CultureInfo.CurrentCulture;

                try
                {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");

                    var aggregateStatsService = new Mock <IAggregateStatsService>(MockBehavior.Strict);
                    var stats = new AggregateStats
                    {
                        Downloads      = 2013,
                        TotalPackages  = 1000,
                        UniquePackages = 500
                    };
                    aggregateStatsService.Setup(s => s.GetAggregateStats()).Returns(Task.FromResult(stats));

                    var controller = CreateController(aggregateStatsService);

                    // Act
                    var result = await controller.Totals() as JsonResult;

                    // Assert
                    Assert.NotNull(result);
                    dynamic data = result.Data;

                    Assert.Equal(2013, data.Downloads);
                    Assert.Equal(500, data.UniquePackages);
                    Assert.Equal(1000, data.TotalPackages);
                }
                finally
                {
                    Thread.CurrentThread.CurrentCulture = currentCulture;
                }
            }
            public void UseClientCultureIfLanguageHeadersIsPresent()
            {
                // Arrange
                var aggregateStatsService = new Mock<IAggregateStatsService>(MockBehavior.Strict);
                var stats = new AggregateStats
                {
                    Downloads = 2013,
                    TotalPackages = 1000,
                    UniquePackages = 500
                };
                aggregateStatsService.Setup(s => s.GetAggregateStats()).Returns(stats);

                var request = new Mock<HttpRequestBase>();
                request.Setup(r => r.UserLanguages).Returns(new string[] { "vi-VN" });

                var controller = CreateController(aggregateStatsService, request);

                // Act
                var result = controller.Totals() as JsonResult;

                // Asssert
                Assert.NotNull(result);
                dynamic data = result.Data;

                Assert.Equal("2.013", (string)data.Downloads);
                Assert.Equal("500", (string)data.UniquePackages);
                Assert.Equal("1.000", (string)data.TotalPackages);
            }
            public void UseServerCultureIfLanguageHeadersIsMissing()
            {
                // Arrange
                var currentCulture = CultureInfo.CurrentCulture;

                try
                {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");

                    var aggregateStatsService = new Mock<IAggregateStatsService>(MockBehavior.Strict);
                    var stats = new AggregateStats
                    {
                        Downloads = 2013,
                        TotalPackages = 1000,
                        UniquePackages = 500
                    };
                    aggregateStatsService.Setup(s => s.GetAggregateStats()).Returns(stats);

                    var controller = CreateController(aggregateStatsService);

                    // Act
                    var result = controller.Totals() as JsonResult;

                    // Asssert
                    Assert.NotNull(result);
                    dynamic data = result.Data;

                    Assert.Equal("2,013", (string)data.Downloads);
                    Assert.Equal("500", (string)data.UniquePackages);
                    Assert.Equal("1,000", (string)data.TotalPackages);
                }
                finally
                {
                    Thread.CurrentThread.CurrentCulture = currentCulture;
                }
            }