Esempio n. 1
0
        public void TestPostAppUsageNew_SunnyDay()
        {
            // Arrange
            string         userId      = "TestUser";
            string         appName     = "TestApp";
            int            timeUsed    = 15;
            AppEnvironment environment = AppEnvironment.Windows;

            List <AppUsage> testAppUsages = new List <AppUsage>();

            AppUsage testAppUsage = CreateAppUsage(appName, timeUsed, userId, environment);

            testAppUsages.Add(testAppUsage);

            var appUsageAdministratorMock = new Mock <IAppUsageAdministrator>();

            appUsageAdministratorMock.Setup(admin => admin.SaveAppUsage(testAppUsage));

            var      appUsageProviderMock = new Mock <IAppUsageProvider>();
            AppUsage nullAppUsage         = null;

            appUsageProviderMock.Setup(provider => provider.FindByUserAndName(userId, appName)).Returns(nullAppUsage);

            AppUsageController appUsageController = new AppUsageController(appUsageProviderMock.Object, appUsageAdministratorMock.Object);

            // Act
            List <AppUsage> actualAppUsageResults = appUsageController.Post(testAppUsages);

            // Assert
            AppUsage actualAppUsage = actualAppUsageResults.Find(x => x.Name.Equals(appName));
        }
Esempio n. 2
0
        public void TestPostAppUsageUpdate_SunnyDay()
        {
            // Arrange
            string         userId      = "TestUser";
            string         appName     = "TestApp";
            int            timeUsed    = 15;
            AppEnvironment environment = AppEnvironment.Windows;

            int expectedTimeUsed = 30;

            AppUsage        appUsage  = CreateAppUsage(appName, timeUsed, userId, environment);
            List <AppUsage> appUsages = new List <AppUsage>
            {
                appUsage
            };

            AppUsage        expectedAppUsage  = CreateAppUsage(appName, expectedTimeUsed, userId, environment);
            List <AppUsage> expectedAppUsages = new List <AppUsage>
            {
                expectedAppUsage
            };

            var appUsageProviderMock = new Mock <IAppUsageProvider>();

            appUsageProviderMock.Setup(provider => provider.FindByUserAndName(userId, appName)).Returns(appUsage);

            var appUsageAdministratorMock = new Mock <IAppUsageAdministrator>();

            appUsageAdministratorMock.Setup(admin => admin.SaveAppUsage(new AppUsage()));

            AppUsageController appUsageController = new AppUsageController(appUsageProviderMock.Object, appUsageAdministratorMock.Object);

            // Act
            List <AppUsage> actualAppUsages = appUsageController.Post(appUsages);
            AppUsage        actualAppUsage  = actualAppUsages.Find(x => x.Name.Equals(appName));

            // Assert
            Assert.AreEqual(expectedAppUsage, actualAppUsage);
        }