Beispiel #1
0
    public async Task CreatePersonAsync_Success()
    {
        //
        // Arrange
        var schema = MongoService.GetSchema <Person>();
        var p      = new Person {
            FirstName = "BatAsync", LastName = "ManAsync", Active = true
        };

        //
        // Act
        await schema.InsertAsync(p);

        //
        // Assert
        var assertPerson = await schema.FindAsync(p.Id);

        Assert.NotNull(p);
        Assert.True(p.Id != ObjectId.Empty);
        Assert.Equal("BatAsync", assertPerson.FirstName);
        Assert.Equal("ManAsync", assertPerson.LastName);

        //
        // Post db cleanup
        //await ExecutePostTestCleanupAsync<Person>();
        //await Task.Delay(1500); // release a bit of pressure to the code
    }
    public async Task DeleteAsync(TIdField id)
    {
        ConsoleOutput.Write(GetType());

        try
        {
            Connect();

            var schema   = _mongoService.GetSchema <TModel>();
            var foundTag = await schema.DeleteAsync(id);
        }
        catch (Exception ex)
        {
            ConsoleOutput.Write(GetType(), ConsoleMessage.Create($"{ex.Message}"));

            //TODO: BaseMongoService class will be relocated to Nautilus experimental mongo project. need to refactor this as well
            throw new NautilusMongoDbException(ex.Message, ex);
        }
    }
Beispiel #3
0
    public void Use_CollectionNameAttribute_Conventions()
    {
        #region Arrange
        //var schemaTypes = new List<Type>
        //    {
        //        typeof(UserSchema),
        //        typeof(CategorySchema),
        //        typeof(PersonSchema),
        //        typeof(CategoryDetailSchema)
        //    };

        //MongoService = MongoInitializer.CreateMongoService(schemaTypes, DatabaseName);
        //MongoService.Connect();
        #endregion

        #region Act
        var userSchema           = MongoService.GetSchema <User>();
        var personSchema         = MongoService.GetSchema <Person>();
        var categorySchema       = MongoService.GetSchema <Category>();
        var categoryDetailSchema = MongoService.GetSchema <CategoryDetail>();
        #endregion

        #region Assert
        Assert.NotNull(userSchema);
        Assert.NotNull(personSchema);
        Assert.NotNull(categorySchema);
        Assert.NotNull(categoryDetailSchema);
        #endregion
    }