Esempio n. 1
0
        public async Task Create_ModelNull_Exception()
        {
            var taskSubjectCommand = new TaskSubjectCommand(
                _loggerMock.Object,
                _cosmosDbMock.Object,
                _taskSubjectCollectionOptionsMock.Object,
                _clientFactoryMock.Object);

            _clientMock.Setup(action => action.UpsertDocumentAsync(
                                  It.IsAny <Uri>(),
                                  It.IsAny <object>()))
            .ReturnsAsync(() =>
            {
                var returnValue = new Document();
                var response    =
                    returnValue.ToResourceResponse(HttpStatusCode.Created, new Dictionary <string, string>());
                response.Resource.Id = "newId";
                return(response);
            });

            Assert.Throws <ArgumentException>(() =>
            {
                taskSubjectCommand.Create((TaskSubjectEntity)null).GetAwaiter().GetResult();
            });
        }
Esempio n. 2
0
        public async Task Create_Model_newId()
        {
            var taskSubjectCommand = new TaskSubjectCommand(
                _loggerMock.Object,
                _cosmosDbMock.Object,
                _taskSubjectCollectionOptionsMock.Object,
                _clientFactoryMock.Object);

            _clientMock.Setup(action => action.UpsertDocumentAsync(
                                  It.Is <Uri>(uri => uri.ToString() == "dbs/DatabaseId/colls/ContainerId"),
                                  It.Is <object>(obj =>
                                                 (obj as TaskSubjectEntity) != null && (obj as TaskSubjectEntity).Uid == "1" &&
                                                 (obj as TaskSubjectEntity).Object == "o1")))
            .ReturnsAsync(() =>
            {
                var returnValue = new Document();
                var response    =
                    returnValue.ToResourceResponse(HttpStatusCode.Created, new Dictionary <string, string>());
                response.Resource.Id = "newId";
                return(response);
            });

            var result = await taskSubjectCommand.Create(new TaskSubjectEntity
            {
                Uid    = "1",
                Object = "o1"
            });

            result.Should().NotBeNull();
            result.Should().Be("newId");

            _clientMock.Verify();
        }
Esempio n. 3
0
        public void Get_Ui_NotFoundModel()
        {
            var taskSubjectCommand = new TaskSubjectCommand(
                _loggerMock.Object,
                _cosmosDbMock.Object,
                _taskSubjectCollectionOptionsMock.Object,
                _clientFactoryMock.Object);

            _clientMock.Setup(action => action.CreateDocumentQuery <TaskSubjectEntity>(It.IsAny <Uri>()))
            .Returns(new EnumerableQuery <TaskSubjectEntity>(new List <TaskSubjectEntity>
            {
                new TaskSubjectEntity
                {
                    Uid    = "1",
                    Object = "o1"
                },
                new TaskSubjectEntity
                {
                    Uid    = "1",
                    Object = "o2"
                },
                new TaskSubjectEntity
                {
                    Uid    = "3",
                    Object = "o3"
                }
            }));

            var result = taskSubjectCommand.Get("4");

            result.Should().BeNull();

            _clientMock.Verify();
        }
Esempio n. 4
0
        public void Get_UiLoadException_exception()
        {
            var taskSubjectCommand = new TaskSubjectCommand(
                _loggerMock.Object,
                _cosmosDbMock.Object,
                _taskSubjectCollectionOptionsMock.Object,
                _clientFactoryMock.Object);

            _clientMock.Setup(action => action.CreateDocumentQuery <TaskSubjectEntity>(It.IsAny <Uri>()))
            .Throws <Exception>();

            Assert.Throws <Exception>(() => { taskSubjectCommand.Get("4"); });
        }
Esempio n. 5
0
        public void List_NoParameters_ListOfModels()
        {
            var taskSubjectCommand = new TaskSubjectCommand(
                _loggerMock.Object,
                _cosmosDbMock.Object,
                _taskSubjectCollectionOptionsMock.Object,
                _clientFactoryMock.Object);

            _clientMock.Setup(action => action.CreateDocumentQuery <TaskSubjectEntity>(It.IsAny <Uri>()))
            .Returns(new EnumerableQuery <TaskSubjectEntity>(new List <TaskSubjectEntity>
            {
                new TaskSubjectEntity
                {
                    Uid    = "1",
                    Object = "o1"
                },
                new TaskSubjectEntity
                {
                    Uid    = "2",
                    Object = "o2"
                },
                new TaskSubjectEntity
                {
                    Uid    = "3",
                    Object = "o3"
                }
            }));

            var result = taskSubjectCommand.List();

            result.Should().NotBeNull();
            result.Count().Should().Be(3);
            result.Should().Contain(item => item.Uid == "1" && item.Object == "o1");
            result.Should().Contain(item => item.Uid == "2" && item.Object == "o2");
            result.Should().Contain(item => item.Uid == "3" && item.Object == "o3");

            _clientMock.Verify();
        }
Esempio n. 6
0
        public async Task Create_ModelLoadException_Exception()
        {
            var taskSubjectCommand = new TaskSubjectCommand(
                _loggerMock.Object,
                _cosmosDbMock.Object,
                _taskSubjectCollectionOptionsMock.Object,
                _clientFactoryMock.Object);


            _clientMock.Setup(action => action.UpsertDocumentAsync(
                                  It.IsAny <Uri>(),
                                  It.IsAny <object>())).Throws(new Exception("Our test exception"));


            Assert.Throws <Exception>(() =>
            {
                taskSubjectCommand.Create(new TaskSubjectEntity
                {
                    Uid    = "1",
                    Object = "o1"
                }).GetAwaiter().GetResult();
            });
        }