Beispiel #1
0
        public void LogTime_FailedOnDBSave_LogException_Success()
        {
            FakeUserLogger      userLogger  = new FakeUserLogger();
            FakeTaskManager     taskManager = new FakeTaskManager();
            FakeTaskAlwaysFalse task        = new FakeTaskAlwaysFalse();
            FakeErrorLogger     errorLogger = new FakeErrorLogger();

            TimeLogger time = new TimeLogger(userLogger, taskManager, task, null, errorLogger);

            var ex = Assert.Throws <Exception>(() => time.LogTime(2, 30, "Working on TimesheetApp"));

            Assert.That(ex.Message, Is.EqualTo(errorLogger.Error.Message));
        }
Beispiel #2
0
        public void uspesnaProveraICuvanjePorudzbine()
        {
            FakeProductChecker productChecker = new FakeProductChecker();
            FakeUserLogger     userLogger     = new FakeUserLogger();
            FakeStockManager   stockManager   = new FakeStockManager();
            FakeOrder          order          = new FakeOrder();
            FakeEmailSender    emailSender    = new FakeEmailSender();

            ProductOrdering productOrdering = new ProductOrdering(userLogger, productChecker, order, emailSender, null, stockManager);

            productOrdering.PlaceOrder(100);
            StringAssert.Contains("*****@*****.**", emailSender.To);
        }
Beispiel #3
0
        public void LogTime_ValidInput_Success()
        {
            FakeUserLogger     userLogger  = new FakeUserLogger();
            FakeTaskManager    taskManager = new FakeTaskManager();
            FakeTaskAlwaysTrue task        = new FakeTaskAlwaysTrue();
            FakeEmailSender    emailSender = new FakeEmailSender();

            TimeLogger time = new TimeLogger(userLogger, taskManager, task, emailSender, null);

            time.LogTime(2, 30, "Working on TimesheetApp");

            StringAssert.Contains("Time logged successfully", emailSender.Title);
        }
Beispiel #4
0
        public void LogTime_SendEmailError_BadData_Fail()
        {
            FakeUserLogger userLogger = new FakeUserLogger();

            userLogger.badEmail = "*****@*****.**";
            FakeTaskManager    taskManager = new FakeTaskManager();
            FakeTaskAlwaysTrue task        = new FakeTaskAlwaysTrue();
            IEmailSender       emailSender = Substitute.For <IEmailSender>();

            TimeLogger time = new TimeLogger(userLogger, taskManager, task, emailSender, null);

            time.LogTime(2, 30, "Working on TimesheetApp");

            emailSender.DidNotReceive().SendEmail("*****@*****.**", "Time logged successfully", "2 hours and 30 minutes successfully logged to task with ID=100");
        }
Beispiel #5
0
        public void LogTime_GetTaskDataError_LogError_Fail()
        {
            string          errorMsg    = "Failed to get the task info";
            FakeUserLogger  userLogger  = new FakeUserLogger();
            FakeTaskManager taskManager = new FakeTaskManager();
            FakeErrorLogger errorLogger = new FakeErrorLogger();

            taskManager.ExceptionWillOccur = new Exception(errorMsg);

            TimeLogger time = new TimeLogger(userLogger, taskManager, null, null, errorLogger);

            var ex = Assert.Throws <Exception>(() => time.LogTime(2, 30, "Working on TimesheetApp"));

            Assert.That(ex.Message, Is.EqualTo(errorMsg));
            Assert.AreEqual(ex, errorLogger.Error);
        }
Beispiel #6
0
        public void greskaNekiOdProizvodaNisuDostupni()
        {
            FakeProductChecker productChecker = new FakeProductChecker();
            FakeUserLogger     userLogger     = new FakeUserLogger();
            FakeStockManager   stockManager   = new FakeStockManager();
            FakeOrder          order          = new FakeOrder();
            FakeErrorLogger    errorLogger    = new FakeErrorLogger();

            productChecker.available = false;

            ProductOrdering productOrdering = new ProductOrdering(userLogger, productChecker, order, null, errorLogger, stockManager);
            Exception       ex = Assert.Throws <Exception>(() => productOrdering.PlaceOrder(100));

            StringAssert.Contains("Some products are not available", ex.Message);
            Assert.AreEqual(ex.Message, errorLogger.exception.Message);
        }
Beispiel #7
0
        public void greskaPrilikomProvereDostupnostiProizvoda()
        {
            FakeProductChecker productChecker = new FakeProductChecker();
            FakeUserLogger     userLogger     = new FakeUserLogger();
            FakeStockManager   stockManager   = new FakeStockManager();
            FakeOrder          order          = new FakeOrder();

            productChecker.exception = new Exception();
            FakeErrorLogger errorLogger = new FakeErrorLogger();

            ProductOrdering productOrdering = new ProductOrdering(userLogger, productChecker, order, null, errorLogger, stockManager);

            Exception ex = Assert.Throws <Exception>(() => productOrdering.PlaceOrder(100));

            Assert.That(ex.Message, Is.EqualTo(errorLogger.exception.Message));
        }
Beispiel #8
0
        public void LogTime_GetUserEmailFail_LogError_Fail()
        {
            string         errorMsg   = "Failed to get user email";
            FakeUserLogger userLogger = new FakeUserLogger();

            userLogger.ExceptionWillOccur = new Exception(errorMsg);
            IErrorLogger errorLogger = Substitute.For <IErrorLogger>();

            TimeLogger time = new TimeLogger();

            time.UserLogger  = userLogger;
            time.ErrorLogger = errorLogger;

            Exception ex = Assert.Throws <Exception>(() => time.LogTime(2, 30, "Working on TimesheetApp"));

            StringAssert.Contains(errorMsg, ex.Message);
            errorLogger.Received().LogError(ex);
        }
Beispiel #9
0
        public void greskaPrilikomSlanjaMejla()
        {
            string             errorMsg       = "Failed to send email";
            FakeProductChecker productChecker = new FakeProductChecker();
            FakeUserLogger     userLogger     = new FakeUserLogger();
            FakeStockManager   stockManager   = new FakeStockManager();
            FakeOrder          order          = new FakeOrder();
            FakeEmailSender    emailSender    = new FakeEmailSender();

            emailSender.exception = new Exception(errorMsg);
            //FakeErrorLogger errorLogger = new FakeErrorLogger();
            IErrorLogger errorLogger = Substitute.For <IErrorLogger>();

            ProductOrdering productOrdering = new ProductOrdering(userLogger, productChecker, order, emailSender, errorLogger, stockManager);
            Exception       ex = Assert.Throws <Exception>(() => productOrdering.PlaceOrder(100));

            errorLogger.Received().LogError(ex.Message);
            StringAssert.Contains("Failed to send email", ex.Message);
        }
Beispiel #10
0
        public void greskaPrilikomSkidanjaProizvodaSaLagera()
        {
            FakeProductChecker productChecker = new FakeProductChecker();
            FakeUserLogger     userLogger     = new FakeUserLogger();
            FakeStockManager   stockManager   = new FakeStockManager();

            stockManager.exception = new Exception();
            IErrorLogger errorLogger = Substitute.For <IErrorLogger>();

            ProductOrdering productOrdering = new ProductOrdering();

            productOrdering.ProductChecker = productChecker;
            productOrdering.UserLogger     = userLogger;
            productOrdering.StockManager   = stockManager;
            productOrdering.ErrorLogger    = errorLogger;

            Exception ex = Assert.Throws <Exception>(() => productOrdering.PlaceOrder(100));

            errorLogger.Received().LogError(ex.Message);
        }