예제 #1
0
        public void TestProps_MethodAccess_WrongParams()
        {
            var derived = new DerivedClass();

            try
            {
                int value = derived.InvokeMethod <int>("MathMethod", 12, "aaa", true);
                Assert.Fail("Error expected. ");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Found 3 [MathMethod] method(s) on [DotNetLittleHelpers.Tests.DerivedClass], however none matches the provided arguments: [Int32,String,Boolean]", ex.Message);
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }

            try
            {
                derived.InvokeMethod("AVoidMethod", 12, "aaa", true);
                Assert.Fail("Error expected. ");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Found 1 [AVoidMethod] method(s) on [DotNetLittleHelpers.Tests.DerivedClass], however none matches the provided arguments: [Int32,String,Boolean]", ex.Message);
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }
        }
예제 #2
0
        public void RunTestWithSuppliedDbConfig()
        {
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyDbUnityLoader());

            Assert.IsInstanceOfType(jobOperator, typeof(SimpleJobOperator));
            Type         t           = jobOperator.GetType();
            PropertyInfo f           = t.GetProperty("JobLauncher", BindingFlags.Instance | BindingFlags.Public);
            IJobLauncher jobLauncher = (IJobLauncher)f.GetValue(jobOperator);

            Assert.IsNotNull(jobLauncher);
            Assert.IsInstanceOfType(jobLauncher, typeof(SimpleJobLauncher));
            PropertyInfo   f2            = t.GetProperty("JobRepository", BindingFlags.Instance | BindingFlags.Public);
            IJobRepository jobRepository = (IJobRepository)f2.GetValue(jobOperator);

            Assert.IsNotNull(jobRepository);
            Assert.IsInstanceOfType(jobRepository, typeof(SimpleJobRepository));
            PropertyInfo        f3          = t.GetProperty("JobRegistry", BindingFlags.Instance | BindingFlags.Public);
            IListableJobLocator jobRegistry = (IListableJobLocator)f3.GetValue(jobOperator);

            Assert.IsNotNull(jobRegistry);
            Assert.IsInstanceOfType(jobRegistry, typeof(MapJobRegistry));
            PropertyInfo f4          = t.GetProperty("JobExplorer", BindingFlags.Instance | BindingFlags.Public);
            IJobExplorer jobExplorer = (IJobExplorer)f4.GetValue(jobOperator);

            Assert.IsNotNull(jobExplorer);
            Assert.IsInstanceOfType(jobExplorer, typeof(SimpleJobExplorer));
            FieldInfo       f5  = jobRepository.GetType().GetField("_jobInstanceDao", BindingFlags.Instance | BindingFlags.NonPublic);
            IJobInstanceDao dao = (IJobInstanceDao)f5.GetValue(jobRepository);

            Assert.IsNotNull(dao);
            Assert.IsInstanceOfType(dao, typeof(DbJobInstanceDao));
        }
예제 #3
0
        public async Task CreateGroupController_GroupNotExist_ReturnsConflict()
        {
            // Arrange
            var controller = new GroupsController(new GroupRepositoryStub(), new UserRepositoryStub(),
                                                  new SmartLockRepositoryStub(), new AzureAdRepositoryStub(), _mapper);

            var groupCreationDto = new GroupCreationDto
            {
                Id              = Guid.Parse("c374cb18-862e-4fef-871f-ae08337d1f76"),
                Status          = Status.Active,
                SmartLockGroups = new List <SmartLockCollectionDto>
                {
                    new SmartLockCollectionDto
                    {
                        SmartLockId = Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6")
                    }
                }
            };

            // Act
            var result = await controller.CreateGroup(groupCreationDto);

            // Assert
            Assert.IsInstanceOfType(result.Result, typeof(ConflictObjectResult));
        }
예제 #4
0
        public void TestRegistraUtente()
        {
            Utente utente = new UtenteNormale
            {
                Nome        = "tizio",
                Cognome     = "caio",
                Email       = "*****@*****.**",
                LoginRemoto = true,
                Username    = "******"
            };

            utente.ImpostaPasswordDaOriginale("password");

            // Verifico che non esista
            Assert.IsNull(gestioneUtentiController.ValidaCredenziali("tizio", "password"));

            // Lo registro, e verifico che adesso esiste
            Assert.IsTrue(gestioneUtentiController.Registra(utente));
            IUtente utenteValidato = gestioneUtentiController.ValidaCredenziali("tizio", "password");

            Assert.IsNotNull(utenteValidato);

            // Mi assicuro che sia del tipo giusto
            Assert.IsInstanceOfType(utenteValidato, typeof(UtenteNormale), "L'utente è di tipo sbagliato");
        }
        public void SetupPark_Throws_Exception_When_Parameters_Are_Missing(string commandAsString)
        {
            // arrange
            Exception resultException = null;

            // act
            try
            {
                _commandParameters = _commandExtractor.ExtractFromCommandString(commandAsString);
            }
            catch (Exception exception)
            {
                if (exception.InnerException != null && exception.InnerException.GetType() == typeof(ArgumentException))
                {
                    resultException = exception.InnerException;
                }
                else
                {
                    resultException = exception;
                }
            }

            // assert
            Assert.IsInstanceOfType(resultException, typeof(ArgumentException));
        }
예제 #6
0
        public async Task GetMoviesTest()
        {
            List <MovieDetail> movies = new List <MovieDetail>()
            {
                new MovieDetail()
                {
                    Title = "test_1", Id = "cm1"
                },
                new MovieDetail()
                {
                    Title = "test_2", Id = "cm1"
                },
                new MovieDetail()
                {
                    Title = "test_1", Id = "fm1"
                },
                new MovieDetail()
                {
                    Title = "test_2", Id = "fm1"
                },
            };
            var movieService = new Mock <IMovieService>();

            movieService.Setup(s => s.GetMoviesByComparingPrice()).Returns(() => Task.FromResult(movies));
            MovieController movieController = new MovieController(movieService.Object);
            IActionResult   actionResult    = await movieController.GetMoviesAsync();

            OkObjectResult okResult = actionResult as OkObjectResult;

            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsInstanceOfType(actionResult, typeof(OkObjectResult));
        }
예제 #7
0
        public void ChildModuleThroughSysModules()
        {
            var code = @"# This is what the os module does

import test_import_1
import test_import_2
import sys

sys.modules['test.imported'] = test_import_1
sys.modules['test.imported'] = test_import_2
";

            using (var newPs = SaveLoad(PythonLanguageVersion.V27,
                                        new AnalysisModule("test", "test.py", code),
                                        new AnalysisModule("test_import_1", "test_import_1.py", "n = 1"),
                                        new AnalysisModule("test_import_2", "test_import_2.py", "f = 3.1415")
                                        )) {
                var entry = newPs.NewModule("test2", "import test as t; import test.imported as p");
                AssertUtil.ContainsExactly(
                    entry.Analysis.GetMemberNamesByIndex("t", 0),
                    "test_import_1",
                    "test_import_2",
                    "imported"
                    );
                var p = entry.Analysis.GetValuesByIndex("p", 0).ToList();
                Assert.AreEqual(2, p.Count);
                Assert.IsInstanceOfType(p[0], typeof(BuiltinModule));
                Assert.IsInstanceOfType(p[1], typeof(BuiltinModule));
                AssertUtil.ContainsExactly(p.Select(m => m.Name), "test_import_1", "test_import_2");

                AssertUtil.ContainsExactly(entry.Analysis.GetTypeIdsByIndex("p.n", 0), BuiltinTypeId.Int);
                AssertUtil.ContainsExactly(entry.Analysis.GetTypeIdsByIndex("p.f", 0), BuiltinTypeId.Float);
            }
        }
예제 #8
0
        public static void Throws <TException>(Action action) where TException : Exception
        {
            Exception ex = CaptureException(action);

            MSAssert.IsNotNull(ex, "The expected exception was not thrown");
            MSAssert.IsInstanceOfType(ex, typeof(TException), "The exception thrown was not of the expected type");
        }
        public void When_Put_Expect_Success()
        {
            // Arrange
            var controller = new TimeBookerController(_dbRepository);

            var updatedBooking = new TimeBooker
            {
                Id        = 3,
                IsRemoved = false,
                Created   = new DateTime(2017, 12, 14, 15, 22, 33),
                Project   = "Project Three",
                Time      = "18"
            };

            // Act
            var result             = controller.Put(3, updatedBooking) as OkResult;
            var checkResult        = controller.Get(3);
            var checkContentResult = checkResult as OkNegotiatedContentResult <TimeBooker>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(checkContentResult);
            Assert.IsInstanceOfType(result, typeof(OkResult));
            Assert.AreEqual(updatedBooking.Time, checkContentResult.Content.Time);
        }
예제 #10
0
        public static void Throws <TException>(Action action, string expectedMessage) where TException : Exception
        {
            Exception ex = CaptureException(action);

            MSAssert.IsNotNull(ex, "The expected exception was not thrown");
            MSAssert.IsInstanceOfType(ex, typeof(TException), "The exception thrown was not of the expected type");
            MSAssert.AreEqual(expectedMessage, ex.Message, String.Format("Exception message was not as expected"));
        }
        public void DeleteConfirmedAction_Returns_Printerview()
        {
            RedirectToRouteResult result  = _uut.Create(new Printer()) as RedirectToRouteResult;
            ActionResult          aresult = _uut.DeleteConfirmed(3);

            // Assert.AreEqual("Index", result.RouteValues["Index"]);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
예제 #12
0
        public void Edit_Returns_HttpNotFoundWhenPrinterIsNull()
        {
            var user = new User();

            user.Id = 0;
            ActionResult result = _uut.Edit(user.Id);

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
        public void CreateAction_Returns_IndexViewWhenModelStateIsValid()
        {
            _uut.ModelState.Clear();

            RedirectToRouteResult result = _uut.Create(new Message()) as RedirectToRouteResult;

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            // Assert.AreEqual("Controller", result.RouteValues["dashboard"]);
        }
        public void Delete_Returns_HttpNotFoundWhenPrinterIsNull()
        {
            var printer = new Printer();

            printer.Id = 0;
            ActionResult result = _uut.Delete(printer.Id);

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
        public void Edit_Returns_ViewWhenRun()
        {
            var printer = new Printer();

            printer.Id = 3;
            ActionResult result = _uut.Edit(printer.Id);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
        public void Delete_Returns_HttpNotFoundWhenPrinterIsNull()
        {
            var message = new Message();

            message.Id = 0;
            ActionResult result = _uut.Delete(message.Id);

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
예제 #17
0
        public void DeleteAction_Returns_UsersviewResult()
        {
            //mock.SetupGet(x => x.Users.Create().Email).Returns("*****@*****.**");
            //mock.SetupGet(x => _uut.CurrentUser).Returns(currentUser);
            //_uut.CurrentUser = mock.Object;

            ActionResult result = _uut.Delete(2); //  uut modtager et ID.

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
예제 #18
0
 public void TestParseInvalidString()
 {
     try {
         value.ParseTextEntry("yes");
         Assert.Fail("Invalid string");
     }
     catch (Exception e) {
         Assert.IsInstanceOfType(e, typeof(InvalidEntryException));
     }
 }
        public void DeleteAction_Returns_Messageview()
        {
            var message = new Message();

            message.Id      = 2;
            message.Content = "fielaursen";
            ActionResult result = _uut.Delete(message.Id);

            // ActionResult result = _uut.Delete(2); //  uut modtager et ID.
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
예제 #20
0
        public void WhenCreatingPage_IfNoExecutorFactoryIsRegistered_ShouldUseTheEmulatorFactory()
        {
            //arrange
            ServiceLocator.BrowserCommandExecutorFactory = null;

            //act
            var htmlPage = new HtmlPage(new Uri("http://myapppath"));

            //assert
            UnitTestAssert.IsInstanceOfType(htmlPage.BrowserCommandExecutor, typeof(EmulatedBrowserCommandExecutor));
        }
예제 #21
0
        public void Index_Returns_ActionResult()
        {
            //Arrange
            ShoppinglistsController controller = new ShoppinglistsController();;

            //Act
            var actual = controller.Index();

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ActionResult));
        }
예제 #22
0
        public void Details_Returns_HttpBadRequestWhenIdIsNull()
        {
            var mock        = new Mock <MakerContext>();
            var currentUser = new User();

            mock.Setup(x => x.Users).Equals("*****@*****.**");
            mock.Setup(x => _uut.CurrentUser).Returns(currentUser);

            ActionResult result = _uut.Details(null);

            Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult));
        }
        public void SetupParkReturnsParkComand()
        {
            // arrange

            // act
            _result = _extractor.ExtractFromCommandString(Inputs.CreateDefaultPark);

            // assert
            Assert.IsInstanceOfType(_result, typeof(ICommand));
            Assert.AreEqual("SetupPark", _result.Name);
            Assert.AreEqual(3.ToString(), _result.Parameters["sectors"]);
            Assert.AreEqual(5.ToString(), _result.Parameters["placesPerSector"]);
        }
        public void GetAggregatedLoadProfileData_WhenCalled_ReturnsProperDataType()
        {
            //arrange
            var dummyData = _fixture.Create <IEnumerable <LoadProfileAggregated> >();

            _repo.GetAggregatedData().Returns(dummyData);

            //act
            var response = _controller.GetAggregatedLoadProfileData();

            //assert
            Assert.IsInstanceOfType(response, typeof(IEnumerable <LoadProfileAggregated>));
        }
        public void When_GetById_Expect_NotFound()
        {
            // Arrange
            var controller = new TimeBookerController(_dbRepository);


            // Act
            var result = controller.Get(8);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void StatusReturnStatusCommand(string commandAsString)
        {
            //arange

            //act

            _result = _extractor.ExtractFromCommandString(commandAsString);
            //assert

            Assert.IsInstanceOfType(_result, typeof(ICommand));
            Assert.AreEqual("Status", _result.Name);
            Assert.AreEqual(0, _result.Parameters.Count);
        }
예제 #27
0
        public async Task GroupById_GroupIdNotExist_NotFound()
        {
            // Arrange
            var controller = new GroupsController(new GroupRepositoryStub(), new UserRepositoryStub(),
                                                  new SmartLockRepositoryStub(), new AzureAdRepositoryStub(), _mapper);
            var groupId = Guid.Parse("c374cb18-862e-4fef-871f-ae08337d1234");

            // Act
            var result = await controller.GetGroup(groupId);

            // Assert
            Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult));
        }
예제 #28
0
        public async Task ValidateGetMovieByIdAndProvider_LogicForSerialization()
        {
            var          mockBaseService    = new Mock <IBaseService>();
            var          mockIMemoryCache   = new Mock <IMemoryCache>();
            var          mockIConfiguration = new Mock <IConfiguration>();
            MovieService service            = new MovieService(mockIMemoryCache.Object, mockBaseService.Object);

            mockBaseService.Setup(s => s.GetDataFromExternalAPI(It.IsAny <string>())).Returns(() => Task.FromResult(this.getMockHttpResponseObject()));
            var movieDetail = await service.GetMovieByIdAndProvider("1", cinemaWorld);

            Assert.IsNotNull(movieDetail);
            Assert.IsNotNull(movieDetail.Id);
            Assert.IsInstanceOfType(movieDetail, typeof(MovieDetail));
        }
예제 #29
0
        public void Render_TemplateWithUncoverVariable()
        {
            var tmp = new Template("{{name}},{{greet}}!");

            tmp.Set("name", "万金油");
            try
            {
                string s = tmp.Render();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ArgumentException));
                Assert.AreEqual("模版变量{{greet}}未被使用", e.Message);
            }
        }
        public void When_Delete_Expect_Success()
        {
            // Arrange
            var controller = new TimeBookerController(_dbRepository);

            // Act
            var result        = controller.Delete(3);
            var contentResult = result as OkNegotiatedContentResult <int>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(contentResult);
            Assert.IsInstanceOfType(contentResult, typeof(OkNegotiatedContentResult <int>));
            Assert.AreEqual(3, contentResult.Content);
        }